-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateAccount.java
More file actions
61 lines (59 loc) · 1.83 KB
/
CreateAccount.java
File metadata and controls
61 lines (59 loc) · 1.83 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
//Program that creates a class Account that stores a variable balance. The class has methods to start account, to deposit money, to withdraw money and tell the current balance amount.
import java.util.*;
public class CreateAccount
{
public static void main(String[] args)
{
Account ob = new Account(); //Defaukt Constructor
ob.Traverse();
}
}
class Account
{
public void Traverse()
{
Scanner sc = new Scanner(System.in);
int i=0,num1,balance=0,flag=-1;
while(i!=1)
{
System.out.println("\n\nEnter 1 to Create Account.\nEnter 2 to Deposit Money.\nEnter 3 to Withdraw Money.\nEnter 4 to Check Account Balance.\nEnter 5 to Exit.");
System.out.print("\nEnter your Choice: ");
num1=sc.nextInt();
if(num1<1 || num1>5)
System.out.println("Invalid Choice!! \nEnter a Valid Input..!!");
else
{
switch(num1)
{
case 1:
if(flag==-1)
{
flag=0;
System.out.println("Account created successfully.");
}
else
System.out.println("Invalid Choice!! \nAccount already successfully...!");
break;
case 2:
System.out.print("\nEnter the amount you want to deposit: ");
int temp=sc.nextInt();
balance+=temp;
break;
case 3:
System.out.print("\nEnter the amount you want to withdraw: ");
int temp2=sc.nextInt();
balance-=temp2;
break;
case 4:
System.out.println("Balance in your account is: "+balance);
break;
case 5:
i=1;
System.out.println("Goodbye!! Have a Nice Day....");
break;
}
}
}
sc.close();
}
}