Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
So i made 2 classes, CurrencyConverter and CurrencyConverterTester, and the purpose is to show how many euros are in a certain amount of dollars. But when ever i enter the amount of dollars, the program did not show the amount of euros it is equal to. I need help and I can't figure out what I did wrong. There is a while loop and I used Java Eclipse in order to compile this.

Currency Conversion Class:
Java
/**
 * 
 * @author Nick 
 *
 */
public class CurrencyConversion {

private int moneyD, exRate;

public CurrencyConversion () {  }

public void setDollar(int dollar)
{
	moneyD = dollar;
}
public void setRate(int rate)
{
	exRate = rate;
}
public double getEuro()

{
	return moneyD * exRate;
}

}


Currency Conversion Tester Class:
import java.util.Scanner;
/**
 * 
 * @author Nick 
 *
 */
public class CurrencyConverterTester {

	/**
	 * @param args
	 */
public static void main(String[] args) {
		// TODO Auto-generated method stub

Scanner in = new Scanner(System.in);
CurrencyConversion d = new CurrencyConversion();

System.out.println("How many Euros in one dollar: ");

String exRate = in.next();

System.out.println("Enter dollar value (Q to quit): ");

String  moneyD = in.next();

while (!moneyD.equalsIgnoreCase("Q"))
{
	d.setDollar(Integer.parseInt(moneyD));
	System.out.println(moneyD + " dollar = " + d.getEuro() + " Euro" );
	
	System.out.println("Enter dollar value (Q to quit): ");
	moneyD = in.next();
}
System.out.println("Good Bye!!!");	

}

}
Posted
Updated 25-Oct-12 14:44pm
v2

Your value exRate is "0" and therefor the calculated value from getEuro() is also always 0.

The first request "Enter dollar value (Q to quit):" should not be outside of the loop. I think you can probably delete it, the loop should do it (but needs some more work too).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Oct-12 1:07am    
Good catch, a 5.
I would not have so much patience to delve into such a trivial mess, I think I could 100% trust that you found right thing.

Cheers,
--SA
Do you know that knowledge of middle-school arithmetic is a very basic prerequisite for going to computing?
If x = k × y, k ≠ 0, 
y = (1/k) × x.


By the way, where do you get this k? It's always changing, every working day.

If you cannot sort out your code based on such things, go back to school or just give up. I'm really sorry to say that, but this is well below the typical level of even the beginners asking CodeProject questions. If just the code is messed up, use the debugger and three input values you can easily check up, test values on each step.

Good luck,
—SA
 
Share this answer
 
v4
Comments
TorstenH. 26-Oct-12 0:54am    
What is this? Are you looking for some action? That's totally inappropriate.
Reported as abusive.
Sergey Alexandrovich Kryukov 26-Oct-12 1:00am    
Maybe, but I don't want to remove it. Sorry for irritating you. I'm irritated myself by such questions and still think it's quite appropriate. Do you think every one needs to be politically correct? Why?

And by the way, I still answered on the essence of this problem, quite correctly. Will be you able to argue against it?

Thank you,
--SA
TorstenH. 26-Oct-12 1:03am    
no prob, I'll do it for you.
Sergey Alexandrovich Kryukov 26-Oct-12 1:04am    
Excuse me, do what "it"?
--SA
TorstenH. 26-Oct-12 1:07am    
answer in a valuable way. Not pissing of beginners. Not being an offensive ... you know what.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900