public class Order
{
   private int widgets;
   private double price;

   public Order(double undiscountedUnitPrice)
   {
       price = undiscountedUnitPrice; 
       widgets = 0;
   }

   public void addWidgets(int quantity)
   {
        widgets = widgets+quantity; 
   }

   public double getTotalPrice()
   {
        return price*widgets; 
   }

   public double getUnitDiscount()
   {
        if(widgets>10000)
        {
            if((widgets-10000)/1000>47.5)
                double toTakeOff = (((widgets-10000)/1000)*.10);
                price = (10000*price)+((widgets-10000)*price-toTakeOff);
            else
                price = widgets*price; 
        }
   }
}

on the double toTakeOff is where I get the .class expected.

Thanks!

Put brackets around your second if statement, it's good programming practice to use brackets, even for one line expressions, should you want to add more later.

It should fix your problem I believe.

Odd, it does fine when I compile it, yet the IDE starts to complain if I leave the brackets, as it should. Without the brackets though, I hope you realize your two lines won't be executed in the if statement.

Edited 5 Years Ago by Aviras: n/a

Hm. Then Aviras, you must be right. Could you copy the code with the correct bracket placement. I may have screwed mine up.

Never mind, I figured it out. Thanks for your help, you solved it!

if((widgets-10000)/1000>47.5){
double toTakeOff = (((widgets-10000)/1000)*.10);
price = (10000*price)+((widgets-10000)*price-toTakeOff);
}
else{
price = widgets*price;
}

EDIT: no problem, just mark the thread as solved so it doesn't keep lingering the forums.

Edited 5 Years Ago by Aviras: n/a

This question has already been answered. Start a new discussion instead.