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
klimas
Posts: 1 Joined: Tue Oct 17, 2017 3:34 pm
Contact:
Post
by klimas » Tue Oct 17, 2017 3:40 pm
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: 9804 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Tue Oct 17, 2017 11:46 pm
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:
Post
by Javier » Mon Nov 20, 2017 12:11 pm
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: 9804 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Mon Nov 20, 2017 10:41 pm
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:
Post
by OCAJO1 » Fri Dec 07, 2018 2:24 pm
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: 9804 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Fri Dec 07, 2018 3:16 pm
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:
Post
by OCAJO1 » Fri Dec 07, 2018 3:31 pm
cool. so the next step - on this exam, if both versions are present, does public win?
admin
Site Admin
Posts: 9804 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Fri Dec 07, 2018 3:36 pm
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:
Post
by aevora » 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.
admin
Site Admin
Posts: 9804 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Wed May 27, 2020 9:24 am
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:
Post
by aevora » Wed Jul 29, 2020 11:14 am
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: 9804 Joined: Fri Sep 10, 2010 9:26 pm
Contact:
Post
by admin » Wed Jul 29, 2020 10:02 pm
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 .
Users browsing this forum: No registered users and 1 guest