How should you write methods in the ElectricAccount class at line n1 so that the member variable bill…?

Given the following two classes: How should you write methods in the ElectricAccount class
at line n1 so that the member variable bill is always equal to the value of the member
variable kwh multiplied by the member variable rate? Any amount of electricity used by a
customer (represented by an instance of the customer class) must contribute to the
customer’s bill (represented by the member variable bill) through the method useElectricity
method. An instance of the customer class should never be able to tamper with or decrease
the value of the member variable bill.

Given the following two classes: How should you write methods in the ElectricAccount class
at line n1 so that the member variable bill is always equal to the value of the member
variable kwh multiplied by the member variable rate? Any amount of electricity used by a
customer (represented by an instance of the customer class) must contribute to the
customer’s bill (represented by the member variable bill) through the method useElectricity
method. An instance of the customer class should never be able to tamper with or decrease
the value of the member variable bill.

A.
Option A

B.
Option B

C.
Option C

D.
Option D



Leave a Reply 12

Your email address will not be published. Required fields are marked *


vepr85

vepr85

B

public void add(double kWh){

if(kWh > 0){

this.kWh += kWh;
this.bill = this.rate * this.kWh;
}
}

Bruno

Bruno

The answer is B.
The solution in A allows to decrease the value of bill using negative numbers as a parameter.
The solution in C doesn’t work because the method is private.
The solution in D allows to set the Bill directly (basically tampering with the bill variable).
The only correct solution is B as it eliminates all the problems in the other 3 solutions.

jotun

jotun

right on bruh

bella

bella

The TestKing answer is Option A. And it compiles fine.

Vendetta

Vendetta

Did exam MAY 17, 2017…This question was seen

Answer: B

giosefer

giosefer

Hi Vendetta,
in your exam, how many questions show in this thread did you find? is valid this forum ?

Thanks.

Vendetta

Vendetta

once u see me make a comment that mean it was seen. I will also tell u the correct answer.