Click here to Skip to main content
11,428,281 members (51,927 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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:
/**
 * 
 * @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 25-Oct-12 13:27pm
Edited 25-Oct-12 15:44pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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).
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v4
Comments
TorstenH. at 26-Oct-12 0:54am
   
What is this? Are you looking for some action? That's totally inappropriate.
Reported as abusive.
Sergey Alexandrovich Kryukov at 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. at 26-Oct-12 1:03am
   
no prob, I'll do it for you.
Sergey Alexandrovich Kryukov at 26-Oct-12 1:04am
   
Excuse me, do what "it"?
--SA
TorstenH. at 26-Oct-12 1:07am
   
answer in a valuable way. Not pissing of beginners. Not being an offensive ... you know what.
Sergey Alexandrovich Kryukov at 26-Oct-12 1:16am
   
No, I don't :-) I don't use bad words and don't even hint them, really wish you to do the same.

You should know that I usually answer in quite a valuable ways, and many confirm it. If I have less patience than some other people, at least I don't pretend I'm nicer then I am. Hope you can understand that. And some poor beginners deserve some negatives, for everyone's good. You hardly can convince me in the opposite.

Can we finally close the issue?

Thank you,
--SA
TorstenH. at 26-Oct-12 1:02am
   
Have you been drunk or something?
Sergey Alexandrovich Kryukov at 26-Oct-12 1:04am
   
OK, please without personal offenses. You expressed your opinion and even reported; it should be enough. I'm fine, thank you. Let's not lower ourselves that badly into saying bad words, etc.
--SA

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



Advertise | Privacy | Mobile
Web01 | 2.8.150428.2 | Last Updated 26 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100