In this simple java program the user is asked for
account no , current meter reading and previous meter reading and then calculates the total amount using the electricity usage for that account. When the user enter
0 as the account no the program stop by showing the total
amount for all accounts.
The program is already doing it but there is a slight mistake which I could not figure out.
1- When the program starts if user enter 0 as account no
The program should show the message. No account has been processed. But while entering if user enters 0 as account no it should add up all the previous account amounts and show.
attached is the code snippet and the program sample
out put exactly how it should do..
A help is highly appreciated.
Thanks

account no , current meter reading and previous meter reading and then calculates the total amount using the electricity usage for that account. When the user enter
0 as the account no the program stop by showing the total
amount for all accounts.
The program is already doing it but there is a slight mistake which I could not figure out.
1- When the program starts if user enter 0 as account no
The program should show the message. No account has been processed. But while entering if user enters 0 as account no it should add up all the previous account amounts and show.
attached is the code snippet and the program sample
out put exactly how it should do..
A help is highly appreciated.
Thanks
Code:
package e.power.bhd;
import java.util.Scanner;
public class EPowerBhd {
public static void main(String[] args) {
int accountNum;
double cMeter;
double pMeter;
double eUsage;
double totalDueAmount = 0.0;
double Tot = 0.0;
Scanner input = new Scanner(System.in);
do {
System.out.print("Enter Account number (0 to stop ) : ");
accountNum = input.nextInt();
if (accountNum != 0) {
System.out.print("Current meter reading : ");
cMeter = input.nextDouble();
System.out.print("Previous meter reading : ");
pMeter = input.nextDouble();
eUsage = cMeter - pMeter;
System.out.print("Electricity Usage(in kWh) : " + eUsage);
System.out.println();
if (eUsage >= 1 && eUsage <= 200) {
totalDueAmount = 0.218 * eUsage;
} else if (eUsage > 200 && eUsage <= 300) {
totalDueAmount = 0.334 * eUsage;
} else if (eUsage > 300 && eUsage <= 600) {
totalDueAmount = 0.516 * eUsage;
} else if (eUsage > 600 && eUsage <= 900) {
totalDueAmount = 0.546 * eUsage;
} else {
totalDueAmount = 0.571 * eUsage;
}
System.out.println();
System.out.println("Amount number : " + accountNum + "," + " your charge is " + "RM" + totalDueAmount);
System.out.println();
} else {
System.out.println("No account has been processed.");
}
} while (accountNum != 0);
Tot += totalDueAmount;
System.out.println("Total Amount collected = " + "RM" + Tot);
System.out.println("________________________________");
System.out.println("--- DONE ----");
System.out.println("________________________________");
}
}

Comment