Troubling compiling Classes and Objects assignment!
I am new to the forums and to Java. I am having trouble on an assignment.
Prompt:
Create a class called “Foreign” with 5 instance data: choice (int), country (String), dollars (double), conversion value (double), and converted amount (double). Create 7 methods: 1 – a constructor to initialize data (numerics to zero and country to null “”); 2 – a method to display the menu and get a choice (from lab5); 3 - a method to return the choice selected; 4 - a method to get the dollars input from the keyboard, and then assign the appropriate country and conversion rate using the menu choice; 5 – a method to calculate the new converted amount; 6 – a method to display the values vertically with descriptions (see below); and 7 – a toString() method to display the data horizontally with one space between each value (see below). Your toString() method must conform to the predefined syntax for all toString() methods. You do not need the count, total, and average from lab5. Write a second file “Lab6.java” that uses this class, repeats until Quit is selected, instantiates an object and calls all the methods.
Now, I have the Foreign.java done and the Lab6.java. However, I am having issues getting it to compile, and most of the errors appear from my Foreign.java. Any ideas would be great. I essentially just get a bunch of "Foreign.java:40: class, interface, or enum expected"
Code:
:
import java.util.Scanner;
import java.text.NumberFormat;
public class Foreign
{
Scanner read=new Scanner(System.in);
private int choice;
private String country;
private double dollars, value, amount;
NumberFormat dollarForm=NumberFormat.getCurrencyInstance();
public Foreign()
{
choice=0.0;
country="";
dollars=0.0;
value=0.0;
amount=0.0;
}
public void menu()
{
System.out.println("U.S. Dollar to Foreign Currency Exchange");
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:");
choice=read.nextInt();
}
public int getchoice()
}
return choice;
}
public void dollars()
{
System.out.print("\nPlease enter the amount of U.S. Dollars: ");
dollars= read.nextDouble();
switch (choice)
{
case 1:
value = 1.1553;
country = "Canadian Dollars";
break;
case 2:
value = 10.550;
country = "Mexican Peso";
break;
case 3:
value = 117.57;
country = "Japanese Yen";
break;
case 4:
value = .8407;
country = "Euro";
break;
}
}
public void amount()
{
amount=rate*dollars
}
public void vertical()
{
System.out.println("Country = " +country);
System.out.println("Rate = " +dollarForm.format(rate));
System.out.println("Dollars = " +dollarForm.format(dollars));
System.out.println("Converted value = " +dollarForm.format(value));
}
public String toString()
{
String horizontal;
horizontal = country + " " + value + " " + dollars + " " + amount;
return horizontal;
}
}