-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.java
More file actions
45 lines (40 loc) · 927 Bytes
/
Copy pathBankAccount.java
File metadata and controls
45 lines (40 loc) · 927 Bytes
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
import java.util.Scanner;
public class BankAccount
{
private int pin;
private double balance;
public BankAccount(int id, double startBalance) throws NegativePINException, NegativeBalanceException
{
if (id < 0)
{
throw new NegativePINException(id);
}
if (startBalance < 0)
{
throw new NegativeBalanceException(startBalance);
}
balance = startBalance;
}
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
BankAccount acct;
boolean getUserInfo = true;
while (getUserInfo)
{
System.out.println("Please enter your PIN: ");
int pin = keyboard.nextInt();
System.out.println("Please enter the startingBalance: ");
double startBal = keyboard.nextDouble();
try
{
acct = new BankAccount(pin, startBal);
getUserInfo = false;
}
catch (BankAccountException e)
{
System.out.println(e.getMessage());
}
}
}
}