-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsov.java
More file actions
61 lines (51 loc) · 1.27 KB
/
consov.java
File metadata and controls
61 lines (51 loc) · 1.27 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
package mypro;
/*here box defines three constructor overload to initialise the dim of box in various ways*/
import java.util.*;
class box5{
double width;
double height;
double depth;
box5(double w, double h, double d){
width=w;
height=h;
depth=d;
}
//constructor when no dimension specified
box5(){
width=-1;
height=-1;
depth=-1;
}
//constructor when cube is created
box5(double len){
width=height=depth=len;
}
double volume() {
return width*height*depth;
}
}
class boxdemo9{
public static void main(String args[]) {
double w,h,d,l;
System.out.println("Constructing box");
Scanner sc= new Scanner(System.in);
System.out.println("Enter Width: ");
w=sc.nextDouble();
System.out.println("Enter height: ");
h=sc.nextDouble();
System.out.println("Enter depth: ");
d=sc.nextDouble();
System.out.println("Enter len: ");
l=sc.nextDouble();
box5 mybox=new box5(w,h,d);
box5 mybox2=new box5();
box5 mycube=new box5(l);
double vol;
vol=mybox.volume();
System.out.println("Vol of box1: "+vol);
vol=mybox2.volume();
System.out.println("Vol of box2: "+vol);
vol=mycube.volume();
System.out.println("Vol of box3: "+vol);
}
}