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!

Recommended Answers

All 7 Replies

Just to update, I've added the return statements.

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.

That sadly was not the solution

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.