import java.text.DecimalFormat; // for decimal formatted output
import java.util.Scanner; // package needed for GUI
public class ElectricBill4
{
public static void main(
String[] args)
{
DecimalFormat num = new DecimalFormat("$,###.00");
// variables
String Company; // to hold Company input
int AccountNumber; // to hold AccountNumber
String Customer;
double kwhUsed;
double OldMeterReading; // string for inputting OldMeterReading
double NewMeterReading; // string for inputting NewMeterReading
double AmountDue;
double charge = 0.0;
Scanner inputDevice = new Scanner(System.in); // initialize scanner
for ( Customer = 1; Customer <= 10; Customer++)
System.out.print("Enter your Customer: "); // Customer name
Customer = inputDevice.nextLine();
Customer = 1;
while(Customer < 11)
{
System.out.print(Customer);
++Customer;
}
System.out.println("State your company name: "); // Company name
Company = inputDevice.nextLine();
System.out.println("Enter account number: "); // AccountNumber
AccountNumber = inputDevice.nextInt();
System.out.println("What is your old meter reading? "); // OldMeterReading);
OldMeterReading = inputDevice.nextDouble();
System.out.println("What is your new meter reading? "); // NewMeterReading);
NewMeterReading = inputDevice.nextDouble();
// calculate the current electricity usage
kwhUsed = (NewMeterReading - OldMeterReading);
// computations
if(kwhUsed <= 300)
{
charge = 5.00;
}
else if(kwhUsed <= 1000)
{
charge = 5.00 +(0.03*(kwhUsed - 300));
}
else
{
charge = 35.00+(0.02*(kwhUsed - 1000));
}
AmountDue = charge; // calculate the bill
System.out.println("Company name is: " + Company); // company name
System.out.println("Customer name is: " + Customer); // customer
System.out.println("Account number is: " + AccountNumber); // account number
System.out.println("Old Meter Reading is: " + OldMeterReading); // old meter rating
System.out.println("New Meter Reading is: " + NewMeterReading); // new meter rating
System.out.println("Kilowatts per hour used is: " + kwhUsed); // kilowatts per hour
System.out.println("Amount Due is: " + num.format(AmountDue)); // amount due
System.out.println(); //Prints a blank line.
// input as many customers as you wish.
inputDevice.nextLine();
System.out.print("If you want to exit this program, please enter the
word 'stop' in now."+ "\n"
+" Otherwise, enter your name: ");
Customer = inputDevice.nextLine(); // loops back to the Customer.
}
System.out.println("Thank you. Goodbye.");
}
}
I am using jGrasp as an editor.