public class Change{
public static void Change(double salesTotal, double customerPayment){
//Bill:a$130,b$55,c$25,d$5,e$1
//f75cents,g30cents,h1cents
double a,b,c,d,e,f,g,h;
a = b = c = d = e = f = g = h = 0;
double change = customerPayment - salesTotal;
if(change < 0){
IO.reportBadInput();
IO.outputIntAnswer(-1);
return;
}
if(change >= 130){
a = Math.floor(change / 130);
change = change - a * 130;
}
if(change >= 55){
b = Math.floor(change / 55);
change = change - b * 55;
}
if(change >= 25){
c = Math.floor(change / 25);
change = change - c * 25;
}
if(change >= 5){
d = Math.floor(change / 5);
change = change - d * 5;
}
if(change >= 1){
e = Math.floor(change / 1);
change = change - e;
}
if(change >= 0.75){
f = Math.floor(change / 0.75);
change = change - 0.75 * f;
}
if(change >= 0.30){
g = Math.floor(change / 0.30);
change = change - 0.30 * g;
}
if(change >= 0.01){
h = Math.floor(change / 0.01);
change = change - 0.01 * h;
}
IO.outputDoubleAnswer(a);
IO.outputDoubleAnswer(b);
IO.outputDoubleAnswer(c);
IO.outputDoubleAnswer(d);
IO.outputDoubleAnswer(e);
IO.outputDoubleAnswer(f);
IO.outputDoubleAnswer(g);
IO.outputDoubleAnswer(h);
}
}
}
我今年刚刚开始学习编程,所以这是一个菜鸟问题。我的任务要求我开发一种计算销售变化的方法。我已使用Change.Change();
在另一个班级对此进行了测试,并得到了正确的结果。但我的导师说我在这种方法中有一个向上倾斜。谷歌搜索后我不知道出了什么问题。如果我不把这个方法放在一个类中,我应该如何从另一个类中调用它?提前谢谢。