-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
59 lines (57 loc) · 2.13 KB
/
Bank.java
File metadata and controls
59 lines (57 loc) · 2.13 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
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;
public class Bank {
ArrayList<Client> bK;
Scanner s = new Scanner(System.in);
Random r = new Random();
public Bank(){
bK = new ArrayList<>();
}
public void add(Client x) {
bK.add(x);
}
public void printAccounts(){
for( int i =0; i<bK.size(); i++)
bK.get(i).print();
}
//user creates an account with all the values of each account
public void openAccount(){
System.out.println("Enter your name: ");
String cName =s.nextLine();
System.out.println("Enter the Starting amount you would like in your Checkings Account: ");
double startCA = s.nextDouble();
System.out.println("Enter the Starting amount you would like in your Savings Account, with an intrest rate of 2%: ");
double startSA = s.nextDouble();
SavingsAcc sA = new SavingsAcc(r.nextInt(), startSA, 2.0 );
CheckingAccount cA = new CheckingAccount(r.nextInt(), startCA, 100.0 );
Client c = new Client(cName, cA, sA);
add(c);
}
//user inputs for deposit and how much
public void deposit(){
System.out.println("What is your account number?");
int aN = s.nextInt();
int index = searchAccount(aN);
if( index != -1){
System.out.print("How much would you like to deposit:");
double d = s.nextDouble();
s.nextLine();
System.out.println("Which account would you like to deposit to: Checking or Savings?");
String depAcc = s.nextLine();
if(depAcc.equals("checking") || depAcc.equals("Checking") )
bK.get(index).depositCA(d);
else
bK.get(index).depositSA(d);
}
else
System.out.println("Invalid Account Number");
}
//this allows the function to search for the account to deposit in
public int searchAccount(int accNum){
for(int i = 0; i<bK.size(); i ++)
if(bK.get(i).getcheckingAcc().getaccNum() == accNum)
return i;
return -1;
}
}