Question: Design and implement a class name Rectangle to represent rectangle. The class contains 1 import java.util.*; 2 import java.lang.*; Two double data fields named width

 Design and implement a class name Rectangle to represent rectangle. The

Design and implement a class name Rectangle to represent rectangle. The class contains 1 import java.util.*; 2 import java.lang.*; Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. No-arg constructor that creates a default rectangle A constructor that creates a rectangle with the specified width and height. A method named getArea) that returns the area of this rectangle A method named getPerimeter) that returns the perimeter import java.io.*; 4 class Rectangle 6 A test program will create Rectangle objects. Display the width, height, area, and perimeter of each rectangle in this order. NOTE Display the area and perimete as a floating-point number to 2 decimal places. If either width or height, is zero or negtive value, use the deafult value for both width and height and calculate the area and the 1 class DriverMain perimeter using default values. public static void main(String args[]) Scanner input new Scanner(System.in); double w input.nextDouble(); double h nput.nextDouble(); Test Case 4 6 Rectangle testRectangle = new Rectangle(w, h); System.out.println(testRectangle.getwidth)); System.out.println(testRectangle.getHeight()); System. out. printf("%" 2f", test Rectangle. getArea( ) ) ; System.out.println(); System. out. printf("%" 2f", test Rectangle. getPerimeter() ) ; System.out.println); 1.0 1.0 1.00 4.00 9 10 13 16 18 19 20

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!