-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCheckings.java
76 lines (67 loc) · 1.78 KB
/
Checkings.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
//Checkings Java Class
import java.util.*;
import java.io.*;
class Checkings implements Serializable
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
Checkings account = new Checkings();
boolean transaction = true;
while(transaction)
{
//System.out.println(account.checkBalance());
System.out.println("Welcome, make a selection: \n");
System.out.println("1) Check Balance ");
System.out.println("2) Make deposit ");
System.out.println("3) Make withdrawal ");
System.out.println("4) Exit ");
int selection = input.nextInt();
//boolean transaction = true;
switch(selection)
{
case 1:
System.out.println("Your balance is: "+account.checkBalance());
break;
case 2:
System.out.println("How much would you like to deposit?");
double deposit = input.nextDouble();
account.makeDeposit(deposit);
System.out.println("Your new balance is : $"+account.checkBalance());
break;
case 3:
System.out.println("How much would you like to withdraw?");
double withdrawal = input.nextDouble();
account.makeWithdrawal(withdrawal);
System.out.println("Your new balance is : $"+account.checkBalance());
break;
case 4:
transaction = false;
}
}
}//main
private double balance;
public void makeDeposit(double deposit)
{
balance += deposit;
//System.out.println("Your current balance is: ");
//System.out.println(balance);
}//deposit method
public void makeWithdrawal(double withdrawal)
{
if(withdrawal > balance)
{
System.out.println("There aren't enough funds in your account.");
}//if statement
else
balance -= withdrawal;
}//withdrawal method
public double checkBalance()
{
return balance;
}//getter
void setBalance(double balance)
{
this.balance = balance;
}
}//end of class