design a class named Rectangle to represent a rectangle. in the class: two doubl
ID: 3613787 • Letter: D
Question
design a class named Rectangle to represent a rectangle.in the class:
two double data fields for width and height, defaults are 1
string named color -- all red
no-arg constructor that creates default rectangle
a constructor that creates a rect with the specified width andheight
the accessor and mutator methoeds for all three data fields
method for getArea
method for getPerimeter
draw the uml diagram for the class. implement the class. write atest program so that any width and height can be used
display the properties
Explanation / Answer
please rate - thanks test program import java.util.*; class recttester {public static void main(String[] args) {rectangle a= new rectangle(5.2,6.3); System.out.println("The area is "+a.getArea()); System.out.println("The perimeter is "+a.getPerimeter()); } } class class rectangle {private double length=1; private double width=1; private String color="red"; public rectangle(double a,double b) {length=a; width=b; } public double getArea() {return length*width; } public double getPerimeter() {return length*2+width*2; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.