I need the solution of the following program Create a Box class. The program sho
ID: 3647939 • Letter: I
Question
I need the solution of the following program Create a Box class. The program should be able to create three types of boxes, with 0, 1, or 3 parameters. If the box is a cube you should only have to provide the length of one side. You should also be able to specify the length, width, and height of the box. You should also be able to create a box with zero dimensions, using default values. You should be able to perform the following calculations on your box: area and volume. Furthermore, you should be able to make your box larger and smaller in two different ways.Explanation / Answer
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()); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.