-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructorPrb.java
More file actions
34 lines (30 loc) · 1.01 KB
/
ConstructorPrb.java
File metadata and controls
34 lines (30 loc) · 1.01 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
import java.util.Scanner;
public class ConstructorPrb {
double length,breadth;
//parameterized Constructor
public ConstructorPrb (double length, double breadth){
this.length = length;
this.breadth = breadth;
}
double get_area() {
return length * breadth;
}
double get_perimeter() {
return 2 * (length * breadth);
}
public static void main(String args[]){
Scanner input = new Scanner(System.in);
ConstructorPrb[] rooms = new ConstructorPrb[4];
for(int i = 0; i < 4; i++){
System.out.println("Enter Length & Breadth of the room " + (i+1) + ":");
double length = input.nextDouble();
double breadth = input.nextDouble();
rooms[i] = new ConstructorPrb(length,breadth);
}
for(int i = 0;i<4;i++){
System.out.println("\nRoom " + (i + 1) + ":");
System.out.println("Area: " + rooms[i].get_area());
System.out.println("Perimeter: " + rooms[i].get_perimeter());
}
}
}