I'm supposed to write a code for my programming class that will act as though you are ordering something online. I've reached the part where I have the program take the item number put in and return a price (without shipping costs), but every time I run it, it seems to have automatically set the variable I'm using to represent price to 13. It should be set to zero. Here's the part of my code that's giving me issues:
class Order {
public Order() {}
public double price(String odd, double quant, int g) {
double set;
if (g == 1) {
if (odd.equals("AT413")) {
set = (50.03 * quant) + set;
} else if (odd.equals("AT414")) {
set = (60.04 * quant) + set;
} else if (odd.equals("AT415")) {
set = (147.01 * quant) + set;
} else if (odd.equals("AT416")) {
set = (38.00 * quant) + set;
} else if (odd.equals("AT417")); {
set = (13.00 * quant) + set;
}
} else if (g == 2) {
if (odd.equals("AT513")) {
set = (50.03 * quant) + set;
} else if (odd.equals("AT514")) {
set = (50.00 * quant) + set;
} else if (odd.equals("AT515")) {
set = (130.02 * quant) + set;
} else if (odd.equals("AT516")) {
set = (25.03 * quant) + set;
} else if (odd.equals("AT517")); {
set = (13.00 * quant) + set;
}
} else if (g == 3) {
if (odd.equals("AT613")) {
set = (50.03 * quant) + set;
} else if (odd.equals("AT614")) {
set = (86.00 * quant) + set;
} else if (odd.equals("AT615")) {
set = (130.00 * quant) + set;
} else if (odd.equals("AT616")) {
set = (40.04 * quant) + set;
} else if (odd.equals("AT617")); {
set = (13.00 * quant) + set;
}
}
return set;
}
}
I tried a few different things. I had it get the variable set from the main code, but that didn't work because even if I sent down 0 to the class, it still set...set (sorry about that variable name) at 13. I tried getting rid of the +set at the end, but that didn't work because then it just printed out 13 as the order cost, even if I put in the String that's supposed to call up 50.03 for the price. I changed matching prices to see what would happen, and I realized that it's pulling the number it's set the variable at from very last line of code, with AT617, but I don't know why it's doing that or how to fix it. Help would be much appreciated, please.
else if(odd.equals("AT417"));linesetbecause those inner blocks still don't have a final unconditionalelse. What happens when, e.g.,gis3, butodddoesn't equal AT613, AT614, AT615, AT616, or AT617?