I'd appreciate some help with this.
For example, my code is;
class Candy extends DessertItem
{
double weight;
double price;
Candy(String n, double w, double p)
{
super(n);
weight = w;
price = p;
}
public double getCost()
{
double cost = weight*price;
int costinCents = (int)cost*100;
cost = costinCents /100.0;
return cost;
}
public String toString()
{
return name+"\t\t\t\t$" + getCost() + "\n\t" + weight + " lbs @ $" + price;
}
}
And the output is:
Peanut Butter Fudge $8.0
2.25 lbs @ $3.99
Why is it displaying $8.0 instead of $8.97?
Any help would be appreciated! Thanks.