| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package com.zipcodewilmington.bankaccountlab;
-
- import java.util.ArrayList;
- import java.util.InputMismatchException;
- import java.util.Scanner;
-
- public class Atm {
-
- BankAccount account;
- ArrayList<BankAccount> accounts;
- Scanner in = new Scanner(System.in);
-
- public String getNameFromUser (){
- System.out.println("Enter your name");
- String name = in.nextLine();
- return name;
- }
-
- public ArrayList<BankAccount> accountsArray(int num, String name){
- accounts = new ArrayList<>();
- for (int i=0; i<num; i++){
- System.out.println("Enter account name");
- String str = in.next();
- System.out.println("Enter amount");
- double balance = in.nextDouble();
- accounts.add(Account.accessAccount(str, name, balance));
- }
- return accounts;
- }
-
- public double getAmountFromUser(){
- System.out.println("Enter amount");
- double amount = in.nextDouble();
- return amount;
- }
-
- public BankAccount AccountIfo (String str) throws InputMismatchException{
- Class checkFor = str.equals("checkings")
- ? CheckingAccount.class
- : str.equals("savings")
- ? SavingsAccount.class
- : str.equals("business")
- ? BusinessAccount.class
- : null;
-
- BankAccount korrektBankerinoAkkount = null;
- for (BankAccount acc : accounts) {
- if (acc.getClass() == checkFor) korrektBankerinoAkkount = acc;
- }
- return korrektBankerinoAkkount;
- }
-
- public void container(){
- boolean welcome = true;
- String selectedAccount = " ";
- int num = 0 ;
- Scanner in = new Scanner(System.in);
- String name = getNameFromUser();
- while(welcome){
- System.out.println("enter choice:\n 1 to open account\n 2 to deposit\n 3 to withdraw\n 4 to check balance\n 5 to exit");
- int response = in.nextInt();
- switch (response){
- case 1:
- System.out.println("how many accounts to open");
- num = in.nextInt();
- accountsArray(num, name);
- break;
- case 2:
- System.out.println("choose account to deposit to");
- selectedAccount = in.next();
- AccountIfo(selectedAccount).depositMoney(getAmountFromUser());
- break;
- case 3:
- System.out.println("choose account to withdraw from");
- selectedAccount = in.next();
- AccountIfo(selectedAccount).withDraw(getAmountFromUser());
- break;
- case 4:
- if(accounts.size() == 1){
- System.out.println("Your "+ accounts.get(0).accountName()+" account balance is " +
- AccountIfo(accounts.get(0).accountName()).getAmount());
- }
- else if (accounts.size()>1) {
- System.out.println("Enter account name");
- selectedAccount = in.next();
- System.out.println("Your " + selectedAccount + " balance is " +
- AccountIfo(selectedAccount).getAmount());
- }
- break;
- case 5:
- welcome = false;
- break;
- default:
- System.out.println("please check your response");
- break;
- }
- }
- }
- }
-
|