-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankAccount.java
96 lines (88 loc) · 2.24 KB
/
BankAccount.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
/**
* Write a description of class Bank here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Scanner;
public class BankAccount
{
private double balance;
public BankAccount()
{
balance=10000;
}
public BankAccount(double startBalance)
{
balance=startBalance;
}
public BankAccount(String str)
{
balance=Double.parseDouble(str);
}
public void deposit(double amount)
{
balance+=amount;
}
public void deposit(String str)
{
balance+=Double.parseDouble(str);
}
public void withdraw(double amount)
{
balance-=amount;
}
public void withdraw(String str)
{
balance-=Double.parseDouble(str);
}
public void setBalance(double b)
{
balance=b;
}
public void setBalance(String str)
{
balance=Double.parseDouble(str);
}
public double getBalance()
{
return balance;
}
public static void main(String[] args)
{
BankAccount bank=new BankAccount();
Scanner input=new Scanner(System.in);
//Double userInput=input.nextDouble();
int choice;
String c="";
do
{
System.out.print("deposit:1 , withdraw:2 , display:3\nYour choice is:");
choice=input.nextInt();
if(choice==1)
{
System.out.println("Enter the amount to deposit:");
Double userInput=input.nextDouble();
bank.deposit(userInput);
}
else if(choice==2)
{
System.out.println("Enter the amount to withdraw:");
Double userInput=input.nextDouble();
bank.withdraw(userInput);
}
else if(choice==3)
{
System.out.print("Your Current Balance is:Rs.");
System.out.println(bank.getBalance());
}
else
{
System.out.println("Invalid");
}
System.out.print("Do you want to continue y or n:");
c = input.next();
}
while(c.equalsIgnoreCase("Y"));
}
}