Question: I need help with a Java program I'm writing. I found most of the answer on this site but the program isn't quite compiling right
I need help with a Java program I'm writing. I found most of the answer on this site but the program isn't quite compiling right so I can't test if it works or not until I fix the error. Here is the assignment - The program should be able to create (instantiate) three types of boxes. The first box would use the default constructor. The second box would be a cube and only need one parameter. The third box would be a rectangular solid and you will send in three parameters to the constructor You should be able to perform the following calculations on your box: surface area of the entire box and volume. Furthermore, you should be able to make your box larger and smaller in the following two different ways: Specify by how much larger (multiplier) you would like to enlarge each dimension of the object. For example, makeLarger(2) would multiply the length, width, and height of the box by 2. Specify the specific amount you would like to add to each dimension of the box. For example, makeLarger(1, 3, 5) would add 1 to the length, 3 to the width, and 5 to the height of the box. Be sure to include methods for the following tasks: 1. Constructors (three) 2. Calculate and return the volume 3. Calculate and return the surface area 4. Enlarge the box by multiplying each side by a number 5. Enlarge the box by adding a number to each side 6. Output the dimensions Demonstrate that your program works properly. You will need to test all of the constructors and all of the methods in your class. Display all results to two decimal places. Input and output should be done with Dialog and Message boxes. Your program should be well documented internally and externally.
Here is what I have so far as code goes -
class Box {
private double side;
private double length;
private double width;
private double height ;
public Box() {}
public Box(double side) {
this.side = side;
}
public Box(double length,double width, double height) {
this.length = length;
this.width = width;
this.height = height;
}
public double findArea() {
if(side>0) {
return side*side*6;
}
else {
return 2*(length+width)*(length+height)*(width+height);
}
}
public findVolume() {
if(side>0) {
return side*side*side;
}
else {
return length*width*height;
}
}
}
class Test {
public static void main(String[] args)
{
Box b1 = new Box(10.0);
System.out.println(b1.findArea());
System.out.println(b1.findVolume());
Box b2 = new Box(10.0,10.0,10.0);
System.out.println(b2.findArea());
System.out.println(b2.findVolume());
Box b3 = new Box();
System.out.println(b3.findArea());
System.out.println(b3.findVolume());
}
}
It is erroring at Box.java:36: error: invalid method declaration; return type required
public findVolume()
^ 1 error
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
