-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjTest.java
More file actions
68 lines (56 loc) · 2.18 KB
/
objTest.java
File metadata and controls
68 lines (56 loc) · 2.18 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
import java.util.*;
class Box{
public static void main(String args[])throws Exception{
Box myBox = new Box();
Scanner sc = new Scanner(System.in);
Dimensions dim = new Dimensions();
double len = dim.getLength();
double bre = dim.getBreadth();
double hgt = dim.getHeight();
int ch = 0;
do{
System.out.println("Press 1, 2 or 3 to: ");
System.out.println("1) Calculate Total Surface Area of the box");
System.out.println("2) Calculate Total Volume of the box");
System.out.println("3) Enter new dimensions of the box");
System.out.println("4) Exit");
ch = sc.nextInt();
switch(ch){
case 1:{
double res = myBox.getTotalSurfaceArea(len, bre, hgt);
System.out.printf("The total surface area of the box is: %.2f",res);
}
break;
case 2:{
double res = myBox.getVolume(dim.lenght, dim.breadth, dim.height);
System.out.printf("The total volume of the box is: %.2f",res);
}
break;
case 3:{
len = dim.getLength();
bre = dim.getBreadth();
hgt = dim.getHeight();
}
break;
case 4:{
System.exit(0);
}
default :{
System.out.println("Enter a valid option ");
}
}
System.out.println();
System.out.println("Do you want to continue?[y/n]");
String c = sc.next();
if(c.equals("n")){
ch = 0;
}
}while(ch!=0);
}
double getTotalSurfaceArea(double lenght, double breadth, double height){
return (2*((lenght*breadth)+(lenght*height)+(breadth*height)));
}
double getVolume(double lenght, double breadth, double height){
return (lenght*breadth*height);
}
}