-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
103 lines (94 loc) · 3.59 KB
/
Account.java
File metadata and controls
103 lines (94 loc) · 3.59 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.util.Scanner;
public class Account {
int balance;
int previousTransaction;
String customerName;
String customerID;
Account(String name, String cid) {
customerName = name;
customerID = cid;
}
void deposit(int amount) {
if (amount != 0) {
balance += amount;
previousTransaction = amount;
}
}
void withdraw(int amount) {
if (amount != 0) {
balance -= amount;
previousTransaction = -amount;
}
}
void getPreviousTransaction() {
if (previousTransaction > 0) {
System.out.println("Deposited: " + previousTransaction);
} else if (previousTransaction < 0) {
System.out.println("Withdrawn: " + Math.abs(previousTransaction));
} else {
System.out.println("No transaction occurred.");
}
}
void calculateInterest(int years) {
double interestRate = .0185;
double newBalance = (balance * interestRate * years) + balance;
System.out.println("The current interest rate is " + (100 * interestRate));
System.out.println("After " + years + " years, your balance will be: " + newBalance);
}
void showMenu() {
char option = '\0';
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome, " + customerName + "!");
System.out.println("Your ID is: " + customerID);
System.out.println();
System.out.println("What would you like to do?");
System.out.println();
System.out.println("A. Check your balance");
System.out.println("B. Make a deposit");
System.out.println("C: Make a withdrawal");
System.out.println("D: View previous transaction");
System.out.println("E: Calculate interest");
System.out.println("F: Exit");
do {
System.out.println();
System.out.println("Enter an option: ");
char option1 = scanner.next().charAt(0);
option = Character.toUpperCase(option1);
System.out.println();
switch (option) {
case 'A':
System.out.println("========================");
System.out.println("Balance = $" + balance);
System.out.println("========================");
System.out.println();
break;
case 'B':
System.out.println("Enter an amount to deposit: ");
int amount = scanner.nextInt();
deposit(amount);
System.out.println();
break;
case 'C':
System.out.println("Enter an amount to withdraw");
int amount2 = scanner.nextInt();
withdraw(amount2);
System.out.println();
break;
case 'D':
System.out.println("========================");
getPreviousTransaction();
System.out.println("========================");
break;
case 'E':
System.out.println("Enter how many years of accrued interest: ");
int years = scanner.nextInt();
calculateInterest(years);
break;
case 'F':
System.out.println("========================");
break;
}
} while (option != 'F');
System.out.println("Thank you for banking with us!");
}
}