Question: 1-Write a test program that creates an array of three objects; first two objects are created via using the default constructor while the third via
1-Write a test program that creates an array of three objects; first two objects are created via using the default constructor while the third via using the second constructor.
2. Attributes for the first two objects should be entered via prompting the user to enter the appropriate attributes. The data should then read from the keyboard
3. Display both the area and the perimeter for each of the objects.
The code:
public class Cylinder {
double height;
double radious;
Cylinder(){}
public Cylinder(double height, double radious) {
this.height = height;
this.radious = radious;
}
public double getSurfaceArea() {
return height*radious;
}
public double getVolume(){
return 2*(radious+height);
}
public String toString(){
return "The area of the rectangle : " +getSurfaceArea()
+"\t The perimeter of the rectangle :" +getVolume();
}
public double getHeight() {
return height;
}
public void setHeight(double heigh) {
this.height = height;
}
public double getRadious() {
return radious;
}
public void setRadious(double radious) {
this.radious = radious;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
