-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
51 lines (27 loc) · 1.06 KB
/
Rectangle.java
File metadata and controls
51 lines (27 loc) · 1.06 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class Rectangle {
private float length, breadth;
public void getParameters() {
Scanner scanner = new Scanner(System.in);
System.out.println("\n \t\t Rectangle Calculator");
System.out.print("-> Enter the length of the rectangle: ");
this.length = scanner.nextFloat();
System.out.print("-> Enter the breadth of the rectangle: ");
this.breadth = scanner.nextFloat();
scanner.close();
}
public float computePerimeter() {
return 2 * (this.length + this.breadth);
}
public float computeArea() {
return (this.length * this.breadth);
}
public static void main(String args[]) {
Rectangle rectangle = new Rectangle();
rectangle.getParameters();
float area = rectangle.computeArea();
float perimeter = rectangle.computePerimeter();
System.out.printf("\nThe area of the rectangle is: %.2f \n", area);
System.out.printf("The perimeter of the rectangle is: %.2f \n", perimeter);
}
}