简体   繁体   中英

troubles with object validation and assigning values

So In this piece of code I'm going to post I'm trying to make it so that say you enter a bucket size of 3, Sense you picked the bucket size of 3 its suppose to make the value of the bucket bee 300$. when calculated in the rental profit method. But i've tried to arrange this code in many different ways but I cannot fix this problem. Can someone please give me some tips on how I should be doing this?

public void SetBucketSize(int b)
   { 

       if (bucket >6 || bucket <0)
       {
         System.out.println("Enter valid Bucket Size(1-5)");
       }

          if (bucket == 1)
          {

             BucketSize = 100;

          }
          if (bucket == 2)
          {

            BucketSize = 200;
          }
          if (bucket == 3)
          {

            BucketSize = 300;;
          }
          if (bucket == 4)
          {

            BucketSize = 400;
          }
          if (bucket == 5)
          {
            BucketSize = 500;
          }

        BucketSize = b;    
   }

public int GetBucketSize()
          {
             return this.BucketSize;
          }



@Override
    public int RentalProfit()  
    {
      return (RentalRate * RentalDays + BucketSize); 

    }
public void SetBucketSize(int b) {
    if (b < 1 || b > 5) {
        System.out.println("Enter valid...");
        return;
    }
    BucketSize = b * 100;
}

SetBucketSize has a parameter named b , and does eventually execute BucketSize = b , but all the code before that is entirely wrong.

Guard condition allows values 0 to 6, but there is only if statements for value 1 to 5, so they don't cover 0 and 6 itself.

Also the code assigns to BucketSize , but that gets overridden by the final BucketSize = b , so in short, all the code is meaningless and does nothing.

I'm amazed that the code even compiles, because where does bucket even come from?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM