import java.util.Scanner;
public class Ebill {
public static void main(String args[]) {
// Declaring variables
int pres, past, units, rate, bill;
Scanner Obj = new Scanner(System.in);
// Getting user inputs
System.out.println("Enter present meter reading: ");
pres = Obj.nextInt();
System.out.println("Enter past meter reading:");
past = Obj.nextInt();
String s = Obj.nextLine();
System.out.println("Enter unit rate:");
rate = Obj.nextInt();
// Calculating consumed units
units = pres - past;
// Calculating the monthly bill
if (units <= 40) {
bill = units * rate;
} else {
bill = 40 * rate + (units - 40) * (rate * 2);
}
// Printing the consumed number of units and the bill
System.out.println("Number of units consumed is " + units);
System.out.println("Electricity bill for the month is " + bill);
System.out.println(s);
}
}
Comments
Post a Comment