Guest_imported
New member
- Jan 1, 1970
- 0
- 0
- 0
hi,
may I know what is wrong with my codes below? The problem that I am facing now is that the value of the total_price is always the same, 0. I think the problem lies in the if-else statements...but I cannot see anything that is wrong with it. Can anyone who is kind enough to help me spot it?
Codes:
public static void calculation(Vector sold, c1 a, c1 b, c1 c, c1 d, c1 e, c1 f, c1 g )
{
double total_price = 0.00;
c1 p, q, r, s, t , u, v;
while(sold.size() != 0) {
System.out.println(((Item)sold.firstElement()).getcode());
if(((Item)sold.firstElement()).getcode() == "c1" {
p = a;
total_price += p.getprice();
p.sold();
}
else if(((Item)sold.firstElement()).getcode() == "c2" {
q = b;
total_price += q.getprice();
q.sold();
}
else if(((Item)sold.firstElement()).getcode() == "c3" {
r = c;
total_price += r.getprice();
r.sold();
}
else if(((Item)sold.firstElement()).getcode() == "p1" {
s = d;
total_price += s.getprice();
s.sold();
}
else if(((Item)sold.firstElement()).getcode() == "p2" {
t = e;
total_price += t.getprice();
t.sold();
}
else if(((Item)sold.firstElement()).getcode() == "k1" {
u = f;
total_price += u.getprice();
u.sold();
}
else if(((Item)sold.firstElement()).getcode() == "k2"{
v = g;
total_price += v.getprice();
v.sold();
}
sold.remove(0);
}//while
System.out.println("Total amount due: $" + total_price);
}//sold
Thanks