0% found this document useful (0 votes)
20 views

Square

The document defines a Rectangle class with width and height properties and methods to calculate the area and perimeter of rectangle objects created with different width and height values.

Uploaded by

Mr. X
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Square

The document defines a Rectangle class with width and height properties and methods to calculate the area and perimeter of rectangle objects created with different width and height values.

Uploaded by

Mr. X
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

public class Square{

public static void main(String[] args){


// Create a Rectangle with width 4 and height 40
Rectangle rectangle1 = new Rectangle(4, 40);

System.out.println("\n Rectangle 1");


System.out.println("-------------");
System.out.println("Width: " + rectangle1.width);
System.out.println("Height: " + rectangle1.height);
System.out.println("Area: " + rectangle1.getArea());
System.out.println("Perimeter: " + rectangle1.getPerimeter());

// Create a Rectangle with width 3.5 and height 35.9


Rectangle rectangle2 = new Rectangle(3.5, 35.9);

System.out.println("\n Rectangle 2");


System.out.println("-------------");
System.out.println("Width: " + rectangle2.width);
System.out.println("Height: " + rectangle2.height);
System.out.println("Area: " + rectangle2.getArea());
System.out.println("Perimeter: " + rectangle2.getPerimeter());
}
Rectangle(double Width,double Height){
width = Width;
height = Height;
}
double getArea(){
return widht*height;
}
double getPerimeter(){
return (widht+height)*2;
}
}

You might also like