import java.util.Scanner;


public class ISPBilling
{
	private static Scanner keyboard = new Scanner(System.in);
	
	public static void main(String[] args)
	{
		System.out.println("Dukes ISP Billing");
		System.out.println();
		
		char pkg = readPackage("Enter the package code (A, B, or C): ");
		double hours = readHours("Enter the number of hours used: ");
		
		ISPCharge charge = new ISPCharge (pkg, hours);
		
		System.out.println();
		System.out.println("Customer Bill");
		System.out.println();
		System.out.printf("Package: %s\n", charge.getPackage() );
		System.out.printf("Hours Used: %.2f\n\n", charge.getBaseHours() + charge.getAddtlHours());
		if(charge.needAddtlHours())
		{	
			System.out.printf("Base Charge: $%.2f\n", charge.getBase());
			System.out.printf("Additional Hours: %.2f", charge.getAddtlHours());
		}
		System.out.println();
		System.out.printf("Total Charge: $%.2f\n", charge.calcCost());
		System.out.printf("Tax: $%.2f\n", charge.calcTax());
		System.out.println();
		System.out.printf("Pay this Amount: $%.2f\n", charge.calcCost() + charge.calcTax());
	}
	
	public static char readPackage(String prompt)
	{
		char pkg;
		
		System.out.print(prompt);
		pkg = keyboard.next().charAt(0);
		switch(pkg)
		{
			case 'a': pkg = 'A'; break;
			case 'A': break;
			case 'B': break;
			case 'b': pkg = 'B'; break;
			case 'C': break;
			case 'c': pkg = 'C'; break; 
			default:
				System.out.printf("You entered %s. Using A", pkg);
				pkg = 'A';
		}
		
		return pkg;
	}
	
	public static double readHours(String prompt)
	{
		double hours;
		
		System.out.print(prompt);
		if (keyboard.hasNextInt())
		{
			hours = keyboard.nextInt();
			if (hours < 0)
			{
				System.out.printf("You entered %f. Using 0", hours);
				hours = 0;
			}
		}
		else
		{
			System.out.printf("You entered %s. Using 0", keyboard.nextLine());
			hours = 0;
		}
		return hours;
	}
}
