[SOLVED] Cant figure out why its erroring
Below I have to sets of code. My first code called Lab6 should use the second set of code called Foreign. When I compile Lab6 it errors out and I cant figure out why. Please help
Code:
import java.util.Scanner;
import java.text.NumberFormat;
public class Lab6
{
public static void main(String[] args)
{
String more = "Y";
Foreign exchange = new Foreign();
do
{
exchange.menu();
exchange.choice();
exchange.dollars();
exchange.vertical();
System.out.println("\n" + exchange);
System.out.print("\nWould you like to enter another exchange? Y/N ");
more = Keyboard.nextLine();
}
while (Character.toUpperCase(more.charAt(0)) == 'Y');
}
}
Code:
import java.util.Scanner;
import java.text.NumberFormat;
public class Foreign
{
private int choice;
private String country;
private double dollars, rate, amount;
Scanner Keyboard = new Scanner(System.in);
NumberFormat dollarFormat = NumberFormat.getCurrencyInstance();
public Foreign()
{
dollars = 0.0;
rate = 0.0;
amount = 0.0;
country = "null";
}
public void menu()
{
System.out.println("======================================================");
System.out.println(" Foreign Exchange Menu");
System.out.println("======================================================\n\n");
System.out.println("1. U.S. to Canada");
System.out.println("2. U.S. to Mexico");
System.out.println("3. U.S. to Japan");
System.out.println("4. U.S. to Euro");
System.out.println("0. Quit\n");
System.out.print("\nPlease enter your choice:");
}
public void choice()
{
choice = Keyboard.nextInt();
}
public int getchoice()
{
return choice;
}
public void dollars()
{
System.out.print("\nEnter the amount of U.S. Dollars you want to convert: ");
dollars = Keyboard.nextDouble();
if (choice >= 1 && choice < 5)
switch (choice)
{
case 1:
rate = 1.2418;
country = "Canadian Dollars";
break;
case 2:
rate = 14.5436;
country = "Mexican Pesos";
break;
case 3:
rate = 88.9183;
country = "Japanese Yen";
break;
case 4:
rate = 0.774078;
country = "Euros";
break;
default:
System.out.println("======================================================");
System.out.println(" Please select 1 through 4 or 0 to quit: ");
System.out.println("======================================================\n\n\n");
}
amount = dollars * rate;
}
public void vertical()
{
System.out.println("\nCountry = " + country);
System.out.println("Rate = " + rate);
System.out.println("Dollars = " + dollarFormat.format(dollars));
System.out.println("Value = " + amount);
}
public String toString()
{
String line;
line = country + " " + rate + " " + dollars + " " + amount;
return line;
}
}