Currency Exchange Class:
Develop a class currency which converts US dollars to values from 5 countries of your choice. Current exchange rates can be found at http://www.fms.treas.gov/intn.html#rates. The class should define constants for the exchange rates and a private dollar field. Methods might include utilities such as toEuros, toPesos, etc which return the dollar field in the corresponding currency.
Client Application:
Develop a Java application to convert dollars to the desired currency. The end-user should supply the dollar amount and indicate which currency to convert to. The client application should call the appropriate method to obtain the equivalence in the desired currency. Display the dollar amount and it’s equivalent on the monitor. You may use either the Scanner or JOptionPane class for obtaining user input. A sample run using the Scanner class is shown below:
Enter a dollar amount: 5:00
Enter the currency to convert to
(1) euro, (2) pound, (3) taka, (4) yen, (5) rupees :
5.0 dollars = 3.845 euros
You may use any method to indicate the desired currency. However, instructions must be clear to the end-user.
This is my service class
public class CurrencyExchange
{
private double dollar;
private double euro, pound, taka, yen, rupees;
private double currency;
private static final double EURO = 0.7650;
private static final double POUND = 0.6370;
private static final double TAKA = 79.0000;
private static final double YEN = 78.0000;
private static final double RUPEES = 52.2500;
public CurrencyExchange()
{
dollar = 0;
}
public CurrencyExchange(double dollars)
{
dollar = dollars;
}
public void setEuro (double dollars)
{
euro = dollars * EURO;
}
public double getEuro()
{
return euro;
}
public void setPound (double dollars)
{
pound = dollars * POUND;
}
public double getPound()
{
return pound;
}
public void setTaka (double dollars)
{
taka = dollars * TAKA;
}
public double getTaka()
{
return taka;
}
public void setYen (double dollars)
{
yen = dollars * YEN;
}
public double getYen()
{
return yen;
}
public void setRupees (double dollars)
{
rupees = dollars * RUPEES;
}
public double getRupees()
{
return rupees;
}
public double getCurrency()
{
return currency;
}
}
This is my client class
import java.util.Scanner;
public class CurrencyExchangeClient
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a dollar amount: ");
double dollars = in.nextDouble();
System.out.println("Enter the currency to convert to (1) euro, (2) pound, (3) taka, (4) yen, (5) rupees : ");
int response = scan.nextInt;
if (response == 1 || response == 2 || response == 3 || response == 4 || response == 5)
dollars = scan.nextDouble();
switch (response)
{
case 1: getEuro();
break;
case 2: getPound();
break;
case 3: getTaka();
break;
case 4: getYen();
break;
case 5: getRupees();
break;
default: System.out.println("Invalid Response");
}
System.out.println(getCurrency());
}
}
Whenever I compile the program using JGrasp it keeps giving me a missing symbols error, I don’t know why though. It should look like the Example application program.
In addition are the toEuro (method) needed and do I have to remove the constants in private class and just set them up in accessor/mutator methods instead if that helps with the program.
CurrencyExchangeClient.java:14: error: cannot find symbol
int response = scan.nextInt;
^
symbol: variable scan
location: class CurrencyExchangeClient
CurrencyExchangeClient.java:30: error: cannot find symbol
case 5: getRupees();
^
symbol: method getRupees()
location: class CurrencyExchangeClient
Those are just a couple of examples.
Syntax errors and logical errors are there.
You should do like this…
i would recommend you to use eclipse like IDE’s , it will guide you as you write. Read more java books.
Good luck.