I have an assignment for school...Write a program CurrencyCOnverter that asks the user to enter today's price of one dollar in euro. THen the program reads U.S. dollar values and converts each to euro values. I have the following code. It works great until I start putting the loops and then it keeps giving me an answer of zero.
public class CurrencyConverter
{
private double dollars;
private double euros;
private double exchangeRate;
public CurrencyConverter()
{
dollars = 0.0;
exchangeRate = 0.0;
}
public double getDollars()
{
return dollars;
}
public double getExchangeRate()
{
return exchangeRate;
}
public double getEuros()
{
euros = dollars * exchangeRate;
return euros;
}
}
import java.util.Scanner;
public class CurrencyConverterTester
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
CurrencyConverter converter = new CurrencyConverter();
boolean done = false;
while (!done)
{
System.out.print("Enter dollar amount, -1 to quit: ");
double dollars = in.nextDouble();
if (dollars != -1)
{
done = false;
System.out.print("Enter the exchange rate: ");
double exchangeRate = in.nextDouble();
System.out.println(dollars + " dollars = " + converter.getEuros() + " euros");
}
else
{
done = true;
}
}
}
}