[英]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$. 因此,在这段代码中,我将尝试发布它,例如说您输入3的存储桶大小,感觉您选择了3的存储桶大小是为了使存储桶蜂的价值达到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. SetBucketSize
有一个名为b
的参数,并且最终会执行BucketSize = b
,但是之前的所有代码都是完全错误的。
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. 卫队条件允许值0-6,但是只有
if
报表值1到5,所以它们不包括0和6本身。
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. 同样,代码将分配给
BucketSize
,但是最终的BucketSize = b
会覆盖它,因此,简而言之,所有代码都是毫无意义的,什么也不做。
I'm amazed that the code even compiles, because where does bucket
even come from? 我很惊讶该代码甚至可以编译,因为
bucket
甚至来自哪里?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.