Page 1 of 1

About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Tue Oct 17, 2017 3:40 pm
by klimas
Hi,

Please explain me the correct answer where :

Code: Select all

public void addUsage(int bytesUsed){     
if(bytesUsed>0){        
totalUsage = totalUsage + bytesUsed;        
totalBill = totalBill + bytesUsed*costPerByte;     
} 
}
while in the question is :
totalBill is always equal to totalUsage*costPerByte
Thank you :)

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Tue Oct 17, 2017 11:46 pm
by admin
Yes, the total bill in the given option also does equal totalUsage*costPerByte.

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Mon Nov 20, 2017 12:11 pm
by Javier
Hi!

I don´t understand the explanation of the last implementation, when says:
"Bandwidth class is now dependent on some other class".
Because if we do like before this sencence:" totalBill field will not reflect the correct amount unless User also calls updateTotalBill"

Why is not good to make the code in this way? (calling updateTotalBill in the User class)

Thank you very much Enthuware!

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Mon Nov 20, 2017 10:41 pm
by admin
Because you don't have control over how other users of your class may write their code. What if someone who is using this class doesn't make sure that updateTotalBill method is called?

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Fri Dec 07, 2018 2:24 pm
by OCAJO1
Would be correct to say whether the method in the correct choice is designated as public or protected is matter of business requirement rather than encapsulation rules?

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Fri Dec 07, 2018 3:16 pm
by admin
yes, that is correct.

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Fri Dec 07, 2018 3:31 pm
by OCAJO1
cool. so the next step - on this exam, if both versions are present, does public win?

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Fri Dec 07, 2018 3:36 pm
by admin
yes, if only one option has to be selected I would select public, but I'm pretty sure you will not get such option.

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Wed May 27, 2020 8:45 am
by aevora
admin wrote:
Tue Oct 17, 2017 11:46 pm
Yes, the total bill in the given option also does equal totalUsage*costPerByte.
Sorry but I don't see how they are equal. Could you provide an example?

Thanks.

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Wed May 27, 2020 9:24 am
by admin
aevora wrote:
Wed May 27, 2020 8:45 am
admin wrote:
Tue Oct 17, 2017 11:46 pm
Yes, the total bill in the given option also does equal totalUsage*costPerByte.
Sorry but I don't see how they are equal. Could you provide an example?

Thanks.
Let's say the cost per unit is 10. So, if you call the addUsage method twice like this:

addUsage(10)// This will change totalBill to 0 + 10*10, i.e. 100.
addUsage(20)// This will change totalBill to 100 + 20*10, i.e. 300.

So, you can see that totalBill is always equal to total bytes consumed (i.e. 30) * costPerBye (i.e.10) = 300.

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Wed Jul 29, 2020 11:14 am
by aevora
Thanks for the explanation, but I think you are mixing the variable totalUsage with totalBill.
"So, you can see that totalUsage is always equal to total bytes consumed (i.e. 30) * costPerBye (i.e.10) = 300."
totalUsage = totalUsage + bytesUsed;
totalBill = totalBill + bytesUsed*costPerByte;

So it is totalBill which is always equal to totalUsage * costPerByte, as you said here:
Yes, the total bill in the given option also does equal totalUsage*costPerByte.

Re: About Question enthuware.ocajp.i.v8.2.1447 :

Posted: Wed Jul 29, 2020 10:02 pm
by admin
You are right. I have updated the post above to avoid confusion.
thank you for your feedback!