我有两个将美元转换为欧元的课程,但是有一个问题,我需要帮助. [英] I have two classes that convert dollars to euros and there is a problem and I need help.

查看:52
本文介绍了我有两个将美元转换为欧元的课程,但是有一个问题,我需要帮助.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我做了2个类,CurrencyConverter和CurrencyConverterTester,目的是显示一定数量的欧元多少钱.但是,无论何时我输入美元金额,程序都不会显示它等于多少欧元.我需要帮助,我无法弄清楚我做错了什么.有一个while循环,我使用Java Eclipse进行编译.

货币换算类别:

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!!!");	

}

}

推荐答案

您的值exRate为"0",因此,来自getEuro()的计算值也始终为0.

第一个请求输入美元价值(要退出的Q):"不应超出循环范围.我认为您可能可以删除它,循环应该执行它(但还需要做更多的工作).
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).


您知道中学算术知识是继续学习的非常基本的先决条件进行计算?
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.



顺便问一下,您从哪里获得此k?每个工作日,它总是在变化.

如果您无法根据这些信息来整理代码,请回到学校或放弃.我真的很遗憾地说,但这远远低于甚至初学者问CodeProject问题的典型水平.如果只是弄乱了代码,请使用调试器和三个输入值,您可以轻松地检查每个步骤的测试值.

祝你好运,

—SA



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


这篇关于我有两个将美元转换为欧元的课程,但是有一个问题,我需要帮助.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆