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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
klimas
Posts: 1
Joined: Tue Oct 17, 2017 3:34 pm
Contact:

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

Post 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 :)

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, the total bill in the given option also does equal totalUsage*costPerByte.
If you like our products and services, please help us by posting your review here.

Javier
Posts: 66
Joined: Mon Feb 20, 2017 12:31 pm
Contact:

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

Post 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!

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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?
If you like our products and services, please help us by posting your review here.

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

yes, that is correct.
If you like our products and services, please help us by posting your review here.

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post by OCAJO1 »

cool. so the next step - on this exam, if both versions are present, does public win?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

aevora
Posts: 5
Joined: Wed May 06, 2020 2:02 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

aevora
Posts: 5
Joined: Wed May 06, 2020 2:02 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

You are right. I have updated the post above to avoid confusion.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests