-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
104 lines (87 loc) · 3.78 KB
/
Copy pathTest.java
File metadata and controls
104 lines (87 loc) · 3.78 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
104
package labTask3;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
CurrentAccount current = new CurrentAccount(10000);
SavingsAccount savings = new SavingsAccount(3000);
DepositAccount deposit = new DepositAccount(5000);
while (true) {
System.out.println(" Menu:");
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Transfer");
System.out.println("4. Pay Installment (Deposit Account)");
System.out.println("5. Apply Interest");
System.out.println("6. Show Balances");
System.out.println("0. Exit");
System.out.print(" Choose option: ");
int choice = sc.nextInt();
if (choice == 0) {
System.out.println("Exiting...");
break;
}
System.out.println("Select Account:");
System.out.println("1. Current");
System.out.println("2. Savings");
System.out.println("3. Deposit");
int accType = sc.nextInt();
Account selected = null;
if (accType == 1) selected = current;
else if (accType == 2) selected = savings;
else if (accType == 3) selected = deposit;
else {
System.out.println("Invalid account!");
continue;
}
switch (choice) {
case 1:
System.out.print("Enter deposit amount: ");
double d = sc.nextDouble();
selected.deposit(d);
break;
case 2:
System.out.print("Enter withdraw amount: ");
double w = sc.nextDouble();
selected.withdraw(w);
break;
case 3:
if (selected instanceof DepositAccount) {
System.out.println("Cannot transfer from Deposit Account");
break;
}
System.out.println("Transfer TO (1=Current, 2=Savings): ");
int toAcc = sc.nextInt();
Account toAccount = (toAcc == 1) ? current : savings;
System.out.print("Enter transfer amount: ");
double t = sc.nextDouble();
selected.transferTo(toAccount, t);
break;
case 4:
if (selected instanceof DepositAccount) {
System.out.print("Enter installment amount: ");
double inst = sc.nextDouble();
((DepositAccount) selected).payInstallment(inst);
} else {
System.out.println("Only for Deposit Account");
}
break;
case 5:
selected.applyInterest();
break;
case 6:
System.out.println("Balances:");
if(selected instanceof CurrentAccount){
System.out.println("Current: " + current.getBalance());}
if(selected instanceof SavingsAccount){
System.out.println("Savings: " + savings.getBalance());}
if(selected instanceof DepositAccount){
System.out.println("Deposit: " + deposit.getBalance());}
break;
default:
System.out.println("Invalid option!");
}
}
sc.close();
}
}