Hello, I need help creating a class file to do the following things. I do not kn
ID: 3888125 • Letter: H
Question
Hello, I need help creating a class file to do the following things. I do not know how to start the class file, or how to create the constructors to preform the following tasks, such as private variables. The information is processing is in the form of doubles and inside an array. Such as this:
20 10 8
4.5 8.45 12.2
8.0 2.5 4.0
1.0 15.0 18.0
3.5 3.5 3.5
6.0 5.0 10.0
You need to write a program using object oriented programming idea for packages. That is, each package must be considered an object. To achieve this, you must write a class named Package. Make sure to create a Java file for the Package class. Some other required properties of the Package class are as follows.
1. All status variables of the Package class must be private.
2. Write no more than two constructors.
3. Must have a public method named getVolume() that will return the volume of the package.
4. Must have a public method named isCube() that will return true if the package is cubic, false otherwise.
5. The Package class must NOT contain any main method. Feel free to write any additional method in the Package class, as you see fit.
Explanation / Answer
// Package.java
public class Package {
private double width;
private double height;
private double length;
public Package() {
// TODO Auto-generated constructor stub
}
/**
* param width param height param length
*/
public Package(double width, double height, double length) {
this.width = width;
this.height = height;
this.length = length;
}
/**
* return the width
*/
public double getWidth() {
return width;
}
/**
* param width the width to set
*/
public void setWidth(double width) {
this.width = width;
}
/**
* return the height
*/
public double getHeight() {
return height;
}
/**
* param height the height to set
*/
public void setHeight(double height) {
this.height = height;
}
/**
* return the length
*/
public double getLength() {
return length;
}
/**
* param length the length to set
*/
public void setLength(double length) {
this.length = length;
}
/**
* method to return the volume
*
*/
public double getVolume() {
return getHeight() * getLength() * getVolume();
}
/**
* method to check it is cube or not
*/
public boolean isCube() {
if (getLength() == getWidth()) {
if (getLength() == getHeight())
return true;
else
return false;
} else
return false;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.