-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainServer.java
More file actions
164 lines (140 loc) · 6.05 KB
/
MainServer.java
File metadata and controls
164 lines (140 loc) · 6.05 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import java.util.*;
class Account{
String name,acc_type;
int Acc_num,Acc_Balance;
Account(){
}
Account(String n,int acc_num,int b,String a_t){
name=n;
Acc_num=acc_num;
Acc_Balance=b;
acc_type=a_t;
}
}
class create_account extends Account{
create_account(String n,int acc_num,int b,String a_t){
name=n;
Acc_num=acc_num;
Acc_Balance=b;
acc_type=a_t;
}
create_account(){
super();
}
void insert(String n,int acc_num,String a_t){
name=n;
acc_type=a_t;
Acc_num=acc_num;
Acc_Balance=0;
}
void display_details(){
System.out.println("Depositor Name :" +name);
System.out.println("Account Number : "+Acc_num);
System.out.println("Account Balance : "+Acc_Balance);
System.out.println("Account Type : "+acc_type);
}
void credit(int money){
Acc_Balance=Acc_Balance+money;
System.out.println("The current balance in your account is: "+Acc_Balance);
}
void debit(int mon){
Acc_Balance=Acc_Balance-mon;
System.out.println("The current balance in your account is: "+Acc_Balance);
}
}
public class MainServer {
public static void main(String args[]){
String user_name=null,type;
type = null;
int balance=0,tmp=0;
int withd=0;
//generate Random Account Number
int aNumber = 0;
aNumber = (int)((Math.random() * 9000)+1000);
create_account user = new create_account("user",0,0,"savings");
Scanner in = new Scanner(System.in);
Scanner strng=new Scanner(System.in);
int userChoice;
boolean quit = false;
do {
System.out.println("1. Create Account");
System.out.println("2. Deposit money");
System.out.println("3. Withdraw money");
System.out.println("4. Check balance");
System.out.println("5. Display Account Details");
System.out.println("0. to quit: \n");
System.out.print("Enter Your Choice : ");
userChoice = in.nextInt();
switch (userChoice) {
case 1:
System.out.print("Enter your Name : ");
user_name=strng.nextLine();
System.out.print("Enter Account Type : ");
type=in.next();
user.insert(user_name, aNumber, type); // inserted
System.out.println("\n\tYour Account Details\n\tDont Forget Account Number\n");
System.out.println("**************************");
user.display_details();
break;
case 2:
System.out.print("Enter your account Number : ");
tmp=in.nextInt();
if(tmp==user.Acc_num){
System.out.print("Enter Amount Of Money : ");
balance=in.nextInt();
user.credit(balance);
System.out.println("\t Successfully Deposited.");
}
else
System.out.println("Wrong Account Number.");
break;
case 3:
System.out.print("Enter your account Number : ");
tmp=in.nextInt();
if(tmp==user.Acc_num){
if(user.Acc_Balance==0)
System.out.print("Your Account is Empty.");
else{
System.out.print("Enter Amount Of Money : ");
withd=in.nextInt();
if(withd>user.Acc_Balance){
System.out.print("Enter Valid Amount of Money : ");
withd=in.nextInt();
}
else
System.out.println("The Amount withdrawn is "+withd);
user.debit(withd);
}
}
else
System.out.println("Wrong Account Number.");
break;
case 4:
System.out.print("Enter your Account Number : ");
tmp=in.nextInt();
if(tmp==user.Acc_num){
System.out.println("Your Current Balance : "+user.Acc_Balance);
}
else
System.out.println("Wrong Account Number.");
break;
case 5:
System.out.print("Enter your Account Number :");
tmp=in.nextInt();
if(tmp==user.Acc_num){
user.display_details();
}else
System.out.println("Wrong Accoount Number.");
break;
case 0:
quit = true;
break;
default:
System.out.println("Wrong Choice.");
break;
}
System.out.println("\n");
} while (!quit);
System.out.println("Thanks !");
}
}