-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
32 lines (26 loc) · 932 Bytes
/
Rectangle.java
File metadata and controls
32 lines (26 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
public class Rectangle {
float length, breadth, area, perimeter;
public void read(Rectangle rec) {
Scanner sc= new Scanner(System.in);
System.out.print("Enter the length of the rectangle: ");
rec.length = sc.nextFloat();
System.out.print("Enter the breadth of the rectangle: ");
rec.breadth = sc.nextFloat();
sc.close();
}
public void calculate(Rectangle rec) {
rec.area = rec.length * rec.breadth;
rec.perimeter = 2 * (rec.length + rec.breadth);
}
public void display(Rectangle rec) {
System.out.println("Area of the rectangle: " + rec.area);
System.out.println("Perimeter of the rectangle: " + rec.perimeter);
}
public static void main(String args[]) {
Rectangle rec = new Rectangle();
rec.read();
rec.calculate();
rec.display();
}
}