-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHalima.java
More file actions
119 lines (98 loc) · 3.54 KB
/
Halima.java
File metadata and controls
119 lines (98 loc) · 3.54 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
import java.util.Scanner;
class Halima {
private static String name;//for taking name input
private static char acctype;//for taking user input about account type
private static int balance=0;//balance declared to 0 so if user not create account it will be considered 0
private static int deposit;//for deposit money
private static int withdraw;//for withdraw
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);//for taking input
int option;//declare outside bcz of loop
do
{
System.out.println("what do you want??\n1.create an account\n2.deposit money\n3.withdraw money\n4.Display information\n5.exit");
option=sc.nextInt();
sc.nextLine();//consume leftover line new character
switch(option){
case 1:
System.out.println("Open New Account");
opennewacc(sc);
break;
case 2:
System.out.println("Deposit Money");
depositmoney(sc);
break;
case 3:
System.out.println("Withdraw Money");
withdrawmoney(sc);
break;
case 4:
System.out.println("Display Information");
displayinfo();
break;
case 5:
System.out.println("Exiting......");
break;
default:
System.out.println("ERROR!! You Entered a Wrong Number");
}
}
while(option!=5);
sc.close();//finish taking input
}
private static void opennewacc(Scanner sc){
System.out.println("What's your name?");
name=sc.nextLine();
System.out.println("which type of account do u want to create??\n Press s for saving\n Press c for current");
acctype=sc.nextLine().charAt(0);
if (acctype == 's' || acctype == 'c')
{
System.out.println("how much money do you want to deposit??");
balance=sc.nextInt();
sc.nextLine();
System.out.println("your Account is created succesfully!");
}
else
{
System.out.println(" ERROR Creating Account! ");
}
}
private static void depositmoney(Scanner sc){
System.out.println("how much money do you want to deposit??");
deposit=sc.nextInt();
balance+=deposit;
System.out.println("your Balance is" + balance);
}
private static void withdrawmoney(Scanner sc){
System.out.println("how much money do you want to withdraw?");
withdraw=sc.nextInt();
if(withdraw<=balance){
balance-=withdraw;
}
if (withdraw==0){
System.out.println("your withdraw is not possible");
}
else {
System.out.println("your withdraw is not possible");
}
System.out.println("your Balance is" + balance);
}
private static void displayinfo(){
System.out.println("your name is " + name);
System.out.println("your account type is " + getAccountType());
System.out.println("your Balance is " + balance);
}
public static String getAccountType()
{
String ayesha = "";
if (acctype == 's')
{
ayesha = "Savings";
}
else if (acctype == 'c')
{
ayesha = "Current";
}
return ayesha;
}
}