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);
}
}
}
I've just started to learn programming this year so this is a noob question. My assignment asks me to develop a method that computes sales change. I've tested this in another class using Change.Change();
and got correct results. But my instructor says that I have an upcast in this method. After googling I had no idea what went wrong. If I do not put this method in a class, how should I call it from another class? Thanks in advance.