Answer to Question #299468 in Java | JSP | JSF for lolo

Question #299468

a)    The Rectangle class contains:

·        Two instance variables width (double) and length (double).

·        Three constructors as shown. The no-arg constructor initializes the width and length to 1.0.

·        Getter and setter for all the instance variables.

·        Methods getArea() and getPerimeter().

·        Override the inherited toString() method, to return "A Rectangle with width=xxx and length=zzz, which is a subclass of yyy", where yyy is the output of the toString() method from the superclass.




1
Expert's answer
2022-02-18T12:50:55-0500




class Rectangle extends Shape {
	private double width;
	private double length;


	public Rectangle() {
		this.width = 1.0;
		this.length = 1.0;
	}


	public Rectangle(double width, double length) {
		this.width = width;
		this.length = length;
	}


	public Rectangle(double width, double length, String color, boolean filled) {
		super(color, filled);
		this.width = width;
		this.length = length;
	}


	@Override
	public double getArea() {
		return width * length;
	}


	@Override
	public double getPerimeter() {
		return 2 * (width + length);
	}


	public String toString() {
		return "A Rectangle with width=" + width + " and length=" + length + ", which is a subclass of "
				+ super.toString();
	}


	/**
	 * @return the width
	 */
	public double getWidth() {
		return width;
	}


	/**
	 * @param width the width to set
	 */
	public void setWidth(double width) {
		this.width = width;
	}


	/**
	 * @return the length
	 */
	public double getLength() {
		return length;
	}


	/**
	 * @param length the length to set
	 */
	public void setLength(double length) {
		this.length = length;
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS