-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlasticCost.java
More file actions
69 lines (57 loc) · 1.74 KB
/
Copy pathPlasticCost.java
File metadata and controls
69 lines (57 loc) · 1.74 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.Scanner;
// 2D Class
class Plastic2D {
double length, breadth;
int cost_per_sqft = 40;
void getDimensions(double l, double b) {
length = l;
breadth = b;
}
double calculateCost() {
double area = length * breadth;
return area * cost_per_sqft;
}
}
// 3D Class inheriting from 2D
class Plastic3D extends Plastic2D {
double height;
final int cost_per_sqft= 60;
void getDimensions(double l, double b, double h) {
length = l;
breadth = b;
height = h;
}
double calculateCost() {
double volume = length * breadth * height;
return volume * cost_per_sqft;
}
}
// Main class
public class PlasticCost {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 1 for 2D Sheet or 2 for 3D Box:");
int choice = sc.nextInt();
if (choice == 1) {
Plastic2D sheet = new Plastic2D();
System.out.println("Enter length and breadth:");
double l = sc.nextDouble();
double b = sc.nextDouble();
sheet.getDimensions(l, b);
System.out.println("Cost of Plastic Sheet = Rs " + sheet.calculateCost());
}
else if (choice == 2) {
Plastic3D box = new Plastic3D();
System.out.println("Enter length, breadth and height:");
double l = sc.nextDouble();
double b = sc.nextDouble();
double h = sc.nextDouble();
box.getDimensions(l, b, h);
System.out.println("Cost of Plastic Box = Rs " + box.calculateCost());
}
else {
System.out.println("Invalid choice");
}
sc.close();
}
}