import java.util.*;
/**
*Name: Michael Dubendris
*Course: 5002-220-01
*Homework: 2
*Date: 3/20/07
*
*Class: Teller
*Purpose: The purpose of this class is to display bank account information
* and to take in bank account information by the user.
*
* @Author Michael Dubendris
* @Version 1.0
* @see BankAccount
*/
public class Teller
{
public static void main(String [] args)
{
Scanner bbq = new Scanner(System.in);
BankAccount account = new BankAccount();
MyScanner myScan = new MyScanner();
//attributes
int transNumber = 0;
String transType = null;
boolean go = false;
int j = 0;
String name = "Unknown";
double balance = 0;
account.setName(name);
account.setBalance(250);
char another = 'x';
System.out.println("Welcome to the Sopprano Bank");
//set customer name
do
{
System.out.print("Enter the customer name: ");
name = bbq.nextLine();
name.trim();
if(name.length() > 0)
{
account.setName(name);
}
else
{
System.out.println("Error: Enter a valid name");
}
}
while(name.length() == 0);
//set starting balance
do
{
System.out.print("Enter the initial balance: ");
balance = bbq.nextDouble();
if(balance >= 0)
{
account.setBalance(balance);
}
else
{
System.out.println("Error: initial balance must be >= 0");
}
}
while(balance < 0);
// //transaction number method deprecated in HW 2
// //take number of transactions
// do
// {
// System.out.print("Enter the number of transactions to be performed: ");
// try
// {
// transNumber = bbq.nextInt();
// }//end try
// catch(Exception e)
// {
// System.out.println("Error: number of transactions must be an integer value. Exiting...");
// System.exit(1);
// }//end catch
// if(transNumber >= 0)
// {
// go = false;
// }//end if
//
// }//end of do
// while(go == true);
// //end number of transactions
//more deprecated code
// // // // // // // for(j = 0; j < (transNumber * 2); j++)
// // // // // // // {
// // // // // // //
// // // // // // // boolean transaction = false;
// // // // // // // if(j == (transNumber * 2))
// // // // // // // {
// // // // // // // transaction = true;
// // // // // // // }//end if
boolean transaction = true;
do
{
System.out.print("Enter d for deposit or w for withdrawal: ");
transType = bbq.nextLine();
//withdrawal loop
if(transType.startsWith("w")|| transType.startsWith("W"))
{
boolean wd = false;
while(wd == false)
{
System.out.print("Enter the amount to withdraw: ");
double withdrawal = bbq.nextDouble();
transaction = false;
wd = account.withdrawal(withdrawal);
if(wd == true)
{
System.out.println("Status after withdrawal: " + account.getName() + " $" + account.getBalance());
System.out.print("Perform another transaction? (y/n): ");
String newTrans = bbq.next();
another = myScan.nextYN(newTrans.charAt(0));
switch(another)
{
case 'y': transaction = true;
break;
case 'n': transaction = false;
break;
default: System.out.println(another);
}
}//end if
else
{
System.out.println("Error: Withdrawal must be > 0 and <= current balance of $" + account.getBalance());
}//end else
}//end while
}//end if
//deposit loop
if(transType.startsWith("d")|| transType.startsWith("D"))
{
boolean dp = false;
while(dp == false)
{
System.out.print("Enter the amount to deposit: ");
double deposit = bbq.nextDouble();
transaction = false;
dp = account.deposit(deposit);
if(dp == true)
{
System.out.println("Status after deposit: " + account.getName() + " $" + account.getBalance());
System.out.print("Perform another transaction? (y/n): ");
String newTrans = bbq.next();
another = myScan.nextYN(newTrans.charAt(0));
switch(another)
{
case 'y': transaction = true;
break;
case 'n': transaction = false;
break;
default: System.out.println(another);
}
}//end if
else
{
System.out.println("Error: Deposit must be > 0");
}//end else
}//end while
}//end if
// System.out.print("Perform another transaction? (y/n): ");
// String newTrans = bbq.next();
// char another = myScan.nextYN(newTrans.charAt(0));
//
// switch(another)
// {
// case 'y': transaction = true;
// case 'n': transaction = false;
// default: System.exit(1);
// }
}//end do
while(transaction == true);
System.out.printf("Final Account Status: Name: " + account.getName() + " " + "Balance: " + "$%.2f\n", account.getBalance());
}//end of Main
}//end class