-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain4.java
121 lines (114 loc) · 2.74 KB
/
Main4.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main;
import Lab4.*;
import java.util.Scanner;
public class Main4 {
public static void check(int total,int correct) throws ArithmeticException{
if(correct/total == 1);
double res= ((float) correct)/total;
if(res>0.40)
System.out.println("Pass!");
else
System.out.println("Failed!");
}
public static void exp3(String args[]){
double d1,d2;
try{
d1=Double.parseDouble(args[0]);
d2=Double.parseDouble(args[1]);
if(d2==0.0)
throw new ArithmeticException();
double res=d1/d2;
System.out.println("Result : "+res);
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("Please enter the valid args!");
System.out.println(e);
}
catch (ArithmeticException e){
System.out.println("Second argument cannot be zero!");
System.out.println(e);
}
catch (NumberFormatException e){
System.out.println("Only Numerical values are allowed !");
System.out.println(e);
}
catch (Exception e){
System.out.println(e);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int ch=1;
while(ch>0){
System.out.println("Enter the practical Number(0 for exit) : ");
ch=sc.nextInt();
switch(ch){
case 1:
try{
check(0,5);
}
catch (ArithmeticException e) {
System.out.println(e);
}
try{
check(10,6);
}
catch (ArithmeticException e){
System.out.println(e);
}
break;
case 2:
myclass obj=new myclass();
obj.myMethod();
break;
case 3:
exp3(args);
break;
case 4:
stack mystack=new stack(4);
int stkch=0;
while(stkch!=3){
System.out.println("1.push\n2.pop\n3.Exit");
stkch=sc.nextInt();
switch(stkch){
case 1:
System.out.println("Enter the number : ");
mystack.push(sc.nextInt());
break;
case 2:
System.out.println(mystack.pop());
break;
}
}
break;
case 5:
Bank bobj = new Bank();
int bch=0;
while(bch!=4){
System.out.println("1.Deposit\n2.Withdraw\n3.Display\n4.Exit");
bch=sc.nextInt();
switch(bch){
case 1:
System.out.println("Enter the amount : ");
bobj.deposit(sc.nextDouble());
break;
case 2:
try{
bobj.withdraw(sc.nextDouble());
}
catch(ArithmeticException e){
System.out.println("Balance cannot be less than 500");
System.out.println(e);
}
catch(NotEnoughBalance e){
System.out.println(e.getMessage());
}
case 3:
bobj.display();
break;
}
}
}
}
}
}