Design of the Box Class. Objects of this class will represent a box (such as a cardboard box.) The sides of a box are rectangles. A Box will have three essential characteristics: width, height, and length. From these characteristics other values may be calculated: volume and total surface area.
Complete the Constructors. The constructors will initialize the instance variables of the object being constructed. You need to pass three parameters to initialize the three instance variables.
Complete a Method. The documentation for the volume( ) method says it looks like this:
// calculate the volume of the box double volume()
The formula to use is: volume = product of all three sides
class Box
{
// Instance Variables
double length ;
double width ;
double height ;
// Constructors
// Methods
}
CODE:
class Box {
// Instance Variables
double length;
double width;
double height;
// Constructors
//default constructor
public Box(){}
//parametrized constructor
public Box(double length, double width, double height)
{
this.length = length;
this.width = width;
this.height = height;
}
// Methods
// method to calculate volume of the box
public double getVolume(){
return (length * width *
height);
}
//method to calculate surface area of the box
public double getSurfaceArea(){
double surfaceArea;
surfaceArea = 2 * + ((length *
width) + (width * height) + (height * length));
return surfaceArea;
}
}
//Driver class
public class BoxDemo {
//main method
public static void main(String[] args) {
//creating an instance of the Box
class
//by passing the length, width and
height
Box box = new Box(14, 12,
13.2);
//calling the method to get and
display the volume of the box
System.out.println("The volume of
the box is : " + box.getVolume());
//calling the method to get and
display the surface area of the box
System.out.println("The surface
area of the box is : " + box.getSurfaceArea());
}
}
OUTPUT:

Design of the Box Class. Objects of this class will represent a box (such as a...
(Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables to 0. b)...
Long Answer 2: (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables...
Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...
Making a rectangle class in java write a simple class that will represent a rectangle. Later on, we will see how to do this with graphics, but for now, we will just have to use our imaginations for the visual representations ofWthe rectangles. Instance Variables Recall that an object is constructed using a class as its blueprint. So, think about an rectangle on your monitor screen. To actually draw a rectangle on your monitor screen, we need a number of...
In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleType class and overload the following operators: +, -, *, ++, --, ==, !=, >>, and <<. Your program should contain the following features: a. Create a base class named rectangleType with following private data members: • length with double type • width with double type b. rectangleType class should contain the following functions: •...
This Program should run in C++ In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleType class and overload the following operators: +, -, *, ++, --, ==, !=, >>, and <<. Your program should contain the following features: a. Create a base class named rectangleType with following private data members: • length with double type • width with double type b. rectangleType class...
** Using Python 3 ** Write a Box class whose init method takes three parameters and uses them to initialize the length, width and height of a Box. It should also have a method named volume that returns the volume of the Box. Write a function named box_sort (not part of the Box class) that uses insertion sort to sort a list of Boxes from greatest volume to least volume.
****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...
(Demonstrate the Box class from above in a program), (Extra 5 Credits ). Re-use your code from the previous question, add the following functions. Each function worth 1 point. You dont have to implement in order. 1) Overloaded cout’s << that displays attributes of a box. Also overload cin’s >> operator to work with this class for constructing a Box instance using values supplied as console inputs. 2) Overloaded == operator as a member function that returns true if two...
Create a class called Retangle.java that contains two double-precision instance variables named width and height. The class should include all kinds of overloaded constructors. Additionally, there should be two accessor methods, mutator methods, class method named area() that returns the area of a Rectangle object. Inside main(),fully test all methods.