In: Computer Science
//JAVA
//basic please for learning programming 2. Thank you.
Write the Class Variables
Class Box is to have the following private data members:
Write the following Overridden Method
Class Box is to have an overridden equals() method that does the
following:
Write the Get and Get Methods
Class Box is to have standard get/set methods for each data
member
Write the following Auxiliary Method
Class Box is to have an auxiliary method getVolume( ). The method
is to have an access of public and return a value of type double.
The method is to do the following:
Write the Constructors
Class Box is to have two constructors with the following
specifications:
Class: Box
Write the class header
Write the following Overridden Method
Class Box is to have an overridden toString() method that does the
following:
displays the following information in the format presented:
Height: display height of the object
Width: display the width of the object
Length: display the length of the object
Write the following application class: BoxApp.
Class BoxApp is to do the following:
Height: the value of the height property
Width: the value of the width property
Length: the value of the length property
Box.java
public class Box {
private
double height;
private double
width;
private double
length;
public
Box() {
height = 0;
width=0;
length=0;
}
public
Box(double height, double width, double length) {
super();
this.height = height;
this.width = width;
this.length = length;
}
@Override
public boolean
equals(Object obj) {
if (this == obj) {
return true;
}
if (this == null || obj.getClass() !=
this.getClass()) {
return false;
}
Box box = (Box) obj;
return box.getHeight() == this.getHeight()
&& box.getLength() == this.getLength()
&&
box.getWidth() == this.getWidth();
}
//
Auxiliary Method
public double
getVolume() {
return height * width * length;
}
// getters and setters
public
double getHeight() {
return height;
}
public void
setHeight(double height) {
this.height = height;
}
public
double getWidth() {
return width;
}
public void
setWidth(double width) {
this.width = width;
}
public
double getLength() {
return length;
}
public void
setLength(double length) {
this.length = length;
}
@Override
public String
toString() {
return "height:" + height +"\n"+ "width:" +
width +"\n"+ "length:" + length ;
}
BoxApp.java
public class BoxApp
{
public static void main(String[] args) {
Box smallBox= new Box(3,4,5);
Box mediumBox=new Box(60, 7,
8);
Box unknownBox=new
Box(0,0,0);
System.out.println(smallBox.equals(unknownBox));
System.out.println();
System.out.println("The following
information for smallBox");
System.out.println(smallBox.toString());
}
}
}