// Arup Guha
// 1/18/07

// Example to illustrate the use of a GiftCard object.

import java.util.*;

public class Shopping {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);

		// Ask the user to enter their name.		
		System.out.println("Welcome to the Shopping Program.");
		System.out.println("Please enter your first and last name, respectively.");
		String first = stdin.next();
		String last = stdin.next();		
		
		// Give them a gift card.
		System.out.println("Great, you have been given a $50.00 gift card to Macy's. Enjoy!");
		GiftCard macys = new GiftCard(first, last, 50.00);
		
		int ans = 0;
		
		// Continue until the user chooses to quit.
		while (ans != 5) {
			
			ans = menu(); // Get the user's menu choice.
			
			
			// Execute a purchase.
			if (ans == 1) {
				System.out.println("What is the cost of your item?");
				double cost = stdin.nextDouble();
				if (macys.spend(cost))
					System.out.println("Great, your purchase has been made.");
				else
					System.out.println("You do not have enough for that purchase. It has been voided.");
			}
			
			// Add to the user's card.
			else if (ans == 2) {
				System.out.println("How much do you want to add to your card?");
				double add = stdin.nextDouble();
				macys.addAmount(add);
			}
			
			// Transfer the user's card.
			else if (ans == 3) {
				System.out.print("Please enter the name of the person to transfer");
				System.out.println(" the card to, first name followed by last name.");
				first = stdin.next();
				last = stdin.next();		
				macys.transfer(first, last);
			}
			
			// Print out the current Card information.
			else if (ans == 4) {
				System.out.println("Current Card Info: "+macys);
			}
		}
		
	}
	
	// Prints out the menu and returns the user's choice.
	public static int menu() {
		
		Scanner stdin = new Scanner(System.in);
		int ans = 0;
		
		// Loop until a valid choice is made by the user.
		while (ans <= 0 || ans > 5) {
			System.out.println("Here are your choices:");
			System.out.println("1. Buy an item.");
			System.out.println("2. Add money to your card.");
			System.out.println("3. Transfer the card to someone else.");
			System.out.println("4. Print the card information.");
			System.out.println("5. Quit.");
			ans = stdin.nextInt();
			if (ans <= 0 || ans > 5)
				System.out.println("Sorry that is not a valid choice.");
		}
		
		return ans;
	}
}