Hello guys,
I am a complete novice in Java. Just started my course in Computer Science and I was given an assignment to write a code for a programme. The test of the exercise is the following:
Create a Java class called Cube, with the following three methods:
A constructor method which creates a Cube object, the size of which is passed as an argument to the method.
A method which calculates and returns the cube's total surface area (six times the area of one face).
A method which calculates and returns the cube's volume (obtaining by cubing the side length)
Now create a CubeUser class which contains the main() method. Within this, you should prompt for and read in the sizes of three different cubes, and then instantiate each of these as a Cube object. Then, you should print out the surface area and volume of each cube by calling the appropriate methods.
I have created something but I ve got two problems. First, when I try to create a new class called CubeUser within the class Cube and then write "public static void main(String argv[])" I am given a notification for an identification error for static method. So I am not sure how/where should I create the second class CubeUser.
My second issue is whether the programme I have designed is correct. It gives me some results when I test it but specifically I am not sure about the following part of the assignment whether I have done it properly - "you should prompt for and read in the sizes of three different cubes, and then instantiate each of these as a Cube object". Could anyone help me, please?
--- Update ---
Ops I forgot to paste the code. It is the following
public class cube { public cube(double s) { ; } public double surfarea(double oneside) { return (oneside * oneside) * 6; } public double volume(double length) { return length * length * length; } public static void main(String argv[]) { cube cb1 = new cube(30); cube cb2 = new cube(36); cube cb3 = new cube(42); System.out.println("the surface area of cub1 is: " + cb1.surfarea(5)); System.out.println("the surface area of cub2 is: " + cb2.surfarea(6)); System.out.println("the surface area of cub3 is: " + cb3.surfarea(7)); System.out.println("the volume of cub1 is: " + cb1.volume(5)); System.out.println("the volume of cub2 is: " + cb2.volume(6)); System.out.println("the volume of cub3 is: " + cb3.volume(7)); } }