Create Test_1.java
This commit is contained in:
28
Assignment-3/javaparser-1.0.0/Test_1.java
Normal file
28
Assignment-3/javaparser-1.0.0/Test_1.java
Normal file
@@ -0,0 +1,28 @@
|
||||
public class test_1{
|
||||
public int calculate(int x){
|
||||
switch(x){
|
||||
case 1: x += 10;
|
||||
break;
|
||||
case 2: x *= 2:
|
||||
break;
|
||||
default: x = -1;
|
||||
}
|
||||
try{
|
||||
x = riskyOp(x);
|
||||
} catch (Exception e){
|
||||
x = 0;
|
||||
}
|
||||
return finalValue(x);
|
||||
}
|
||||
private int riskyOp(int input) Exception {
|
||||
if (input < 0){
|
||||
throw new Exception("Negative input");
|
||||
}
|
||||
return input + 5;
|
||||
}
|
||||
private int finalValue(int val){
|
||||
return val*2;
|
||||
}
|
||||
|
||||
int result = this.calculate(2);
|
||||
}
|
||||
Reference in New Issue
Block a user