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
?? help
??
B
public void add(double kWh){
if(kWh > 0){
this.kWh += kWh;
this.bill = this.rate * this.kWh;
}
}
D
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.
right on bruh
The TestKing answer is Option A. And it compiles fine.
Answer: B
b
Did exam MAY 17, 2017…This question was seen
Answer: B
Hi Vendetta,
in your exam, how many questions show in this thread did you find? is valid this forum ?
Thanks.
once u see me make a comment that mean it was seen. I will also tell u the correct answer.