/*----------------------------------------------------------------
  FILE: Display.java
  AUTHOR: Arthur Dick
  LAB: 3
  DATE: 18 /09 /04
  PURPOSE: Emulates the display of a simple ATM machine
  ----------------------------------------------------------------*/


import tio.*;

public class Display
{
    public void startScreen()
    {
	System.out.println("Arthur's ATM Service");
	System.out.println();
	System.out.println("Please enter all dollar values as real numbers with no $ signs.");
    }
    
    public char selectionScreen()
    {
	boolean more = true;
	char ans;
	
	do
	    {
		System.out.println();
		System.out.println("d == deposit");
		System.out.println("w == withdrawl");
		System.out.println("b == print balance");
		System.out.println("o == open account");
		System.out.println("c == close account");
		System.out.println("q == quit");
		System.out.println();
		System.out.print("Please choose an option: ");
		ans = (char)Console.in.readChar();
		Console.in.readLine();
		
		if(ans < 'a')
		    ans += ('a' - 'A');  //convert to lower case!
		
		if((ans == 'd') || (ans == 'w') || (ans == 'b') || (ans == 'o') || (ans == 'c') || (ans == 'q'))
		    more = false;
		
		else
		    {
			System.out.println();
			System.out.println("Sorry, unrecognized request.");
			System.out.println("Please try again, or type 'q' to quit");
		    } 
	    } while (more);
	return ans;
    }
    
    public int chooseAccount()
    {
	char ans;
	int selection = -1;
	boolean more = true;
	
	while (more == true) {
	    System.out.println();
	    System.out.println("Select Account:");
	    System.out.println("s == savings");
	    System.out.println("c == chequing");
	    System.out.println("v == visa");
	    System.out.println("1 == extra account 1");
	    System.out.println("2 == extra account 2");
	    System.out.println("q == return to main menu");
	    System.out.println();
	    System.out.print("Please choose an option: ");
	    
	    ans = (char)Console.in.readChar();
	    Console.in.readLine();
	    
	    switch (ans)
		{
		case 's' :
		case 'S' : selection = 0;
		    more = false;
		    break;
		    
		case 'c' : 
		case 'C' : selection = 1;
		    more = false;
		    break;
		    
		case 'v' : 
		case 'V' : selection = 2;
		    more = false;
		    break;
		    
		case '1' : selection = 3;
		    more = false;
		    break;
		    
		case '2' : selection = 4;
		    more = false;
		    break;
		    
		case 'q' : 
		case 'Q' : more = false;
		    break;
		    
		default : System.out.println();
		    System.out.println("Sorry, unrecognized request.");
		    System.out.print("Please try again, or type 'q' to quit");
		}
	}
	return (selection);
    }
    
    public double getDepositAmount()
    {
	double amount = -1.0;
	while (amount < 0.0)
	    {
		System.out.print("Amount to deposit:");
		
		amount = Console.in.readDouble();
		Console.in.readLine();
		
		if(amount < 0.0)
		    System.out.println("Sorry, invalid amount. Please enter a positive number."); // will not allow negative numbers for deposit
	    }
	return amount;
    }
    
    public double getWithdrawAmount(double max)
    {
	double amount = -1.0;	
	while (amount < 0.0)
	    {
		System.out.print("Amount to withdraw:");
		
		amount = Console.in.readDouble();
		Console.in.readLine();
		
		if((amount < 0.0) || (amount > max))
		    System.out.println("Sorry, invalid amount."); // will not allow negative numbers for deposit
	    }
	return amount;
    }
}

