-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathException13320.java
More file actions
46 lines (36 loc) · 1.01 KB
/
Exception13320.java
File metadata and controls
46 lines (36 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
34
35
36
37
38
39
40
41
42
43
44
45
46
class CheckedException extends Exception{
CheckedException(double Dim){
System.out.println("Invalid Dimension "+Dim);
}
}
class Box123{
private double length;
private double width;
private double height;
Box123(double length, double width, double height) throws CheckedException{
if (length<=0)
throw new CheckedException(length);
if (width<=0)
throw new CheckedException(width);
if (height<=0)
throw new CheckedException(height);
this.length = length;
this.height = height;
this.width = width;
}
public double area(){
return 2*(length*width + width*height +height*length);
}
public double volume(){
return length*width*height;
}
}
public class Exception13320 {
public static void main(String[] args) {
try {
Box123 box123 = new Box123(10,0,20);
System.out.println(box123.area());
}catch (CheckedException e){
}
}
}