import java.util.Scanner;

public class SlotsIO 
{
	private Scanner keyboard;
	
	public SlotsIO()
	{
		keyboard = new Scanner(System.in);
	}
	
	public boolean playAgain(String prompt)
	{
		boolean again;
		String input;
		
		again = false;
		
		System.out.print(prompt);
		input = keyboard.nextLine();
		
		if(input.equalsIgnoreCase("YES") || input.equalsIgnoreCase("y"))
			again = true;
		
		return again;
	}
	
	public double readWager(String prompt)
	{
		double wager;
		
		wager = -5;
		do
		{
			System.out.print(prompt);
			if(keyboard.hasNextDouble())
			{
				wager = keyboard.nextDouble();
				keyboard.nextLine();
				if (wager < 0 || wager > 50)
				{
					writeBlank();
					writeError(String.format("$%.2f", wager));
				}
			}
			else
			{
				writeBlank();
				writeError(keyboard.nextLine());
			}
		}while( wager < 0 || wager > 50);
		
		return wager;
	}
	
	public void writeError(String value)
	{
		System.out.println("You entered " + value + ". Enter a positive number < 50.00.");
	}
	
	public void writeResult(double winning)
	{
		if (winning > 0)
			System.out.printf("You won $%.2f!\n", winning);
		else
			System.out.printf("You lose.\n");
	}
	public void writeWelcome()
	{
		System.out.println("Welcome to JMU Slots");
	}
	public void writeSlots(String slots)
	{
		System.out.println(slots);
	}
	
	public void writeBlank()
	{
		System.out.println();
	}
	public void writeGoodbye(double winnings)
	{
		String result;
		if (winnings > 0)
			result = "won " + String.format("$%.2f.", winnings);
		else if (winnings < 0)
			result = "lost " + String.format("$%.2f.", Math.abs(winnings));
		else 
			result = "broke even.";
			
		System.out.println("Goodbye. You " + result);
	}
}
