public class Customer { ElectricAccount acct = new ElectricAccount(); public void useElectricity (double kWh) { acct.addKWh(kWh); } } public class ElectricAccount { private double kWh; private double rate = 0.07; private double bill; //line n1 }
public void addKWh (double kWh) { this.kWh += kWh; this.bill = this.kWh*this.rate;}
public void addKWh (double kWh) { if (kWh > 0) { this.kWh += kWh; this.bill = this.kWh * this.rate; }}
private void addKWh (double kWh) { if (kWh > 0) { this.kWh += kWh; this.bill = this.kWh*this.rate; }}
public void addKWh (double kWh) { if (kWh > 0) { this.kWh += kWh; setBill (this.kWh) ; }}public void setBill (double kWh) { bill = kWh*rate;}