/*
* BankAccountDriver.java Author: DM
*
* Demonstrates the use of
*/
package bankaccountproj;
import java.util.Scanner;
import java.io.*;
public class BankAccountDriver {
public static void main(String[] args) {
//Creates scanners
Scanner fileScan = null;
Scanner lineScan = null;
try{
fileScan = new Scanner(new File("BankAccountInput"));
}
catch(Exception e){
System.out.println(e);
}
//Reads array size from first line in file "BankAccount Input"
int arraySize = fileScan.nextInt();
BankAccount [] currentAccounts = new BankAccount[10];
fileScan.nextLine();
// To demonstrate the use of multiple constructors
BankAccount account1 = new BankAccount("Geoff", "123");
BankAccount account2 = new BankAccount("Helen","234", 100);
BankAccount account3 = new BankAccount("Jameel", "345", 700, 100);
//Creates int i. As long as i is less than arraySize, keep looping.
//i++ increments i after each loop
for (int i = 0; i < arraySize; i++)
{
//Scans next line in the file
String nextLine = fileScan.nextLine();
//Creates new lineScan Scanner
lineScan = new Scanner(nextLine);
//Sets "/" as the delimiter
lineScan.useDelimiter("/");
//Scans in the next int value and assigns it to the variable "type"
int type = lineScan.nextInt();
//Assigns next value to "name"
String name = lineScan.next();
//Assigns next value to "accountNumber"
String accountNumber = lineScan.next();
if(type == 3)
{
currentAccounts = new BankAccount(name, accountNumber);
System.out.println( "Account Name: " + name + " Account Number: " + accountNumber );
}
else if(type == 2)
{
double balance = lineScan.nextDouble();
currentAccounts = new BankAccount(name, accountNumber, balance);
System.out.println( "Account Name: " + name + " Account Number: " + accountNumber );
}
else if(type == 1)
{
double balance = lineScan.nextDouble();
double overdraft = lineScan.nextDouble();
currentAccounts = new BankAccount(name, accountNumber, balance, overdraft);
System.out.println( "Account Name: " + name + " Account Number: " + accountNumber );
}
//Can print out last name but how do you print out all names in array?
if( currentAccounts .isInCredit() )
System.out.println("Accounts not in credit: " + name);
// To demonstrate the use of accessor methods
System.out.println( account1 + " has a balance of " + account1.getBalance() );
System.out.println( account2 + " has an overdraft limit of " + account2.getOverdraftLim() );
if ( account3.isInCredit() )
System.out.println( account3 + " is not overdrawn." );
else
System.out.println( account3 + " is overdrawn." );
account1.deposit(200);
System.out.println( account1 + " now has a balance of " + account1.getBalance() );
String message = account2.withdraw(200);
System.out.println( message );
System.out.println( account3.withdraw(100) );
System.out.println( account3 + " now has a balance of " + account3.getBalance() );
// To demonstrate object interaction
System.out.println( account2.transfer( 50, account1 ) );
System.out.println( account1 + " now has a balance of " + account1.getBalance() );
System.out.println( account2 + " now has a balance of " + account2.getBalance() );
}
}
}