JAVA
design a class named Rectangle to represent a rectangle. The class contains:
A method named getPerimeter() that returns the perimeter.
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.
A 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.
design a class named Rectangle to represent a rectangle. The class contains:
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.
A no-arg constructor that creates a default rectangle.
Draw the UML diagram for the class and then implement the class. Write a test program that creates two Rectangle objects-one with width 4 and height 40 and the other with width 3.5 and height 35.9. Display the width, height, area, and perimeter of each rectangle in this order.
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.
Draw the UML diagram for the class and then implement the class. Write a test program that creates two Rectangle objects-one with width 4 and height 40 and the other with width 3.5 and height 35.9. Display the width, height, area, and perimeter of each rectangle in this order.
please help me fixing the mistake ?
public class Exercise09_01
{
public static void main (String[]
args)
{
Rectangle rectangle1 = new Rectangle(4,40);
Rectangle rectangle2 = new Rectangle(3.5,3.59);
System.out.println("The details of the first rectangel...");
System.out.println("Width of Rectangle1:" +
rectangle1.width);
System.out.println("Height of Rectangle1:" +
rectangle1.height);
System.out.println("Area of Rectangle1:" +
df.format(rectangle1.getArea()));
System.out.println("Perimeter of Rectangle1:"+
rectangle1.getPerimeter());
System.out.println();
System.out.println("The details of the second rectangel...");
System.out.println("Width of Rectangle2:" +
rectangle2.width);
System.out.println("Height of Rectangle2:" +
rectangle2.height);
System.out.println("Area of Rectangle2:" +
df.format(rectangle2.getArea()));
System.out.println("Perimeter of Rectangle2:"+
rectangle2.getPerimeter());
}
}
public class Rectangle
{
double width =
1.0;
double height =
1.0;
Rectangel() {
}
Rectangel(double newWidth, double newHeight)
{
width =
newWidth;
height =
newHeight;
}
double getArea()
{
return width * height;
}
double getPerimeter()
{
return 2*(width + height);
}
}
UML Rectangle class digaram

-------------------------------*-------------------------------*-------------------------------*
/**Test java program for Rectangle class*/
//Exercise09_01.java
import java.text.DecimalFormat;
public class Exercise09_01
{
public static void main (String[] args)
{
Rectangle rectangle1 = new
Rectangle(4,40);
Rectangle rectangle2 = new
Rectangle(3.5,3.59);
/**Create an instace of
DecimalFormat class*/
DecimalFormat df=new
DecimalFormat("#,##.##");
System.out.println("The details of
the first rectangel...");
System.out.println("Width of
Rectangle1:" + rectangle1.width);
System.out.println("Height of
Rectangle1:" + rectangle1.height);
System.out.println("Area of
Rectangle1:" + df.format(rectangle1.getArea()));
System.out.println("Perimeter of
Rectangle1:"+ rectangle1.getPerimeter());
System.out.println();
System.out.println("The details
of the second rectangel...");
System.out.println("Width of
Rectangle2:" + rectangle2.width);
System.out.println("Height of
Rectangle2:" + rectangle2.height);
System.out.println("Area of
Rectangle2:" + df.format(rectangle2.getArea()));
System.out.println("Perimeter of
Rectangle2:"+ rectangle2.getPerimeter());
}
}
-------------------------------*-------------------------------*-------------------------------*
//Rectangle.java
public class Rectangle
{
/**Instance variables */
double width ;
double height;
/*Name of the constructor must match with
* the name of the class, Rectangle*/
public Rectangle()
{
width=1;
height=1;
}
/*Name of the constructor must match with
* the name of the class, Rectangle*/
public Rectangle(double newWidth, double
newHeight)
{
width = newWidth;
height = newHeight;
}
/**Returns area */
public double getArea()
{
return width * height;
}
/**Returns perimeter */
public double getPerimeter()
{
return 2*(width + height);
}
}/**End of Rectangle class*/
-------------------------------*-------------------------------*-------------------------------*
Sample Output:
The details of the first rectangel...
Width of Rectangle1:4.0
Height of Rectangle1:40.0
Area of Rectangle1:1,60
Perimeter of Rectangle1:88.0
The details of the second rectangel...
Width of Rectangle2:3.5
Height of Rectangle2:3.59
Area of Rectangle2:12.56
Perimeter of Rectangle2:14.18
JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify...
Following the example of the Circle class in Section 8.2, design a class named Rectangle to represent a rectangle. The class contains: ■ 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. ■ A 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...
(The Rectangle class) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: ■ 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. ■ A no-arg constructor that creates a default rectangle. ■ A constructor that creates a rectangle with the specified width and height. ■ A method named getArea()...
Please use Java to answer the question. (The Rectangle class) Following the example of the Circle class in Section 8.2, design a class named Rectangle to represent a rectangle. The class contains: ■ 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. ■ A no-arg constructor that creates a default rectangle. ■ A constructor that creates a rectangle with the specified width...
using c++ E2b:Design a class named Rectangle to represent a rectangle . The class contains: (1) Two double data members named width and height which specifies the width and height of the rectangle . (2) A no-arg constructor that creates a rectangle with width 1 and height 1. (3) A constructor that creates a rectangle with the specified width and height . (4) A function named getArea() that returns the area of this rectangle . (5) A function named getPerimeter()...
Within NetBeans, write a Java program for EACH of the following problems. (The Rectangle class) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: · 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. · A no-arg constructor that creates a default rectangle. · A constructor that creates a...
NEEDS TO BE IN PYTHON: (The Rectangle class) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: - Two data fields named width and height. - A constructor that creates a rectangle with the specified width and height. The default values are 1 and 2 for the width and height, respectively. - A method named getArea() that returns the area of this rectangle. - A method named...
// This program uses the programmer-defined Rectangle class. #include "Rectangle.cpp" #include <iostream> using namespace std; int main() { Rectangle rectangle1; Rectangle rectangle2; rectangle1.setLength(10.0); rectangle1.setWidth(5.0); rectangle2.setLength(7.0); rectangle2.setWidth(3.0); cout << "Perimeter of rectangle1 is " << rectangle1.calculatePerimeter() << endl; cout << "Area of rectangle1 is " << rectangle1.calculateArea() << endl; cout << "Perimeter of rectangle2 is " << rectangle2.calculatePerimeter() << endl; cout << "Area of rectangle2 is " << rectangle2.calculateArea() << endl;...
Do exercise 9.1 in the book (page 362, or page 384 of the Comprehensive Version of the book) Also add a method named getDiagonal which computes and returns the diagonal of the rectangle. For example the distance from the top left corner to the bottom right corner. Or equivalently the distance from the top right corner to the bottom left corner. Call this method and display it's output in your test program. for the two Rectangle objects. Here is exercise...
Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects and find their area and perimeter. Instructions Ensure the class file named Rectangle.cpp is open in your editor. In the Rectangle class, create two private attributes named length and width. Bothlength and width should be data type double. Write public set methods to set the values for lengthand width. Write public...
java language
Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...