Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Java language thanks For this problem you will need to write a square supe

ID: 3748585 • Letter: U

Question

Using Java language thanks

For this problem you will need to write a square superclass and 2 subclasses of square. The names and work for each of these classes is as follows Square Define an instance-based field of type double named Length. Make certain the field has proper access protections. You should also define a getter & setter for this field Define a constructor which has a single double parameter: use the value of that parameter to set the initial value of length. Define a method getcircumference() which returns a double and has public access protection. This method should return the sum of the length of the instance's sides (eg, Length * 4). This must be a subclass of square Define a field of type double named height. Make certain the field has proper access protections. You should also define a getter & setter for this field Define a constructor which has two double parameters: use the first parameter to set its tength and the second parameter to set the instance's height. . Make certain that the getCircumference() so that it is correctly defined for a rectangle. This is 2height(* the instance's length) If any work is required (and this may or may not be required), make sure the getter and setter for Length are usable Cube This must be a subclass of square. Define a constructor which has a single double parameter: this parameter should be used to set the initial value of Length (remember that Cube is-a square) Make certain that the getcircunference() so that it is correctly defined for a cube. For any who do not remember (including your instructor), this is 3 times larger than the circumference of a square Define a method getvolume() which returns a double and has public access protection. This method should return the volume of the instance (e.g., Length Length Length). If any work is required (and this may or may not be required), make sure the getter and setter for Length are usable

Explanation / Answer

class Square{

private double length;

public Square(double aLength) {

super();

length = aLength;

}

public double getLength() {

return length;

}

public void setLength(double aLength) {

length = aLength;

}

public double getCircumference(){

return getLength()*4;

}

}

class Rectangle extends Square{

private double height;

public Rectangle(double aLength, double aHeight) {

super(aLength);

height = aHeight;

}

public double getHeight() {

return height;

}

public void setHeight(double aHeight) {

height = aHeight;

}

public double getCircumference(){

return getLength()*2 + getHeight()*2;

}

}

class Cube extends Square{

public Cube(double param){

super(param);

}

public double getCircumference(){

return 3 * (getLength()* 4 );

}

public double getVolume(){

return getLength() * getLength() * getLength();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote