-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.java
More file actions
81 lines (76 loc) · 2.13 KB
/
BankAccount.java
File metadata and controls
81 lines (76 loc) · 2.13 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
//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.Scanner;
//import java.util.*;
class BankAccount
{
String name;
double balance;
void CreateAccount(String n, double b)
{
name = n;
balance = b;
System.out.print("\nAccount Created:");
System.out.println("\nName: " + name);
System.out.println("\nAmount: " + balance);
}
void deposit(double d)
{
if(d > 0.0)
{
balance = balance + d;
}
System.out.print("\nBalance After Deposit: " + balance);
}
void withdraw(double w)
{
if(w > 0.0 && w <= balance)
{
balance = balance - w;
}
System.out.print("\nBalance After Withdrawal: " + balance);
}
double getBalance()
{
return balance;
}
public static void main(String args[])
{
BankAccount s1= new BankAccount();
Scanner in = new Scanner(System.in);
System.out.print("\nEnter your name: ");
String x = in.nextLine();
System.out.print("\nEnter Amount: ");
double y = in.nextDouble();
s1.CreateAccount(x,y);
while(true)
{
System.out.print("\nChoose any method from the following Options ----");
System.out.print("\nOption 1 :: To Deposit Money");
System.out.print("\nOption 2 :: To Withdraw Money");
System.out.print("\nOption 3 :: To Get Balance");
System.out.print("\nOption 4 :: To Exit");
System.out.print("\nSelect your choice: ");
int choice= in.nextInt();
switch(choice)
{
case 1: // To deposit money
System.out.print("\nEnter the amount you would like to deposit: ");
double deposit = in.nextDouble();
s1.deposit(deposit);
break;
case 2: // To withdraw money
System.out.print("\nEnter the amount you would like to withdraw: ");
double withdraw = in.nextDouble();
s1.withdraw(withdraw);
break;
case 3: // To get balance
System.out.print(s1.getBalance());
break;
case 4:
System.exit(0);
default:
System.out.print("\nInvalid choice! Please make avalid choice.");
}
}
}
}