Question

JAVA
*REFER TO THE PICTURES*

Summary Write a program that will calculate the monthly electric charges for a customer given a starting and ending readings from an electric meter. Charges will depend on the actual usage and the results will be displayed to the user Requirements From the user, get the month for the readings From the user, get the starting and ending reading values (in kWh) (integers) Standard rate is 42 cents per kWh Overage rate is 48 cents per kWh If the month is either July, August or September, the rates will be 4 cents higher (standard and overage) The user can enter the month using capitals, lower case, or a mix. So an input of JULY, July, or july all should be okay. *For all other months, it is optional to validate the name of the month, you may just accept it and move on Validate the meter readings, see the sample runs o a negative reading should produce an error o an ending reading that is less than the beginning should produce an error If meter readings are valid o If the usage is less than 100 kWh, the charges will be calculated at standard rate o If the usage is greater than 100 kWh, the charges for the first 100 kWh will be calculated using the standard rate, and every excess kWh (over the 100) will be calculated at the overage rate o In the summer months, the standard and overage rates hike and are 4 cents gher Display the charges in USD with 2 decimals Allow the user to enter readings for more months o Keep a running total of each months charges o Keep a count of how many months were calculated When the user is finished, display a summary of the charges o The total charges for all n months o The total kWh for all n months o The average charge per month o The average kWh per month Match the output shown below. Note that in the sample run with valid input there is a blank line between the input and the displayed computations


0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

import java.text.DecimalFormat;

public class ElectricCharges {

      public static void main(String[] args) {

          

        double charges, totalCharges=0, averageCharge;

        int startReading=0, endReading=0, usage, totalUsage=0, avergeUsage, count=0, flag=0;

       

        //Creating object of Scanner class for standard input

        Scanner stdin = new Scanner(System.in);  

        DecimalFormat df = new DecimalFormat(".00");       //used to print output upto 2 decimal places

        String cont = "yes";

        do { //Reading month from user

               System.out.print("Please enter the month for the reading: ");

               String month = stdin.next();

               month = month.toUpperCase(); //Converting into month uppercase

               //Taking input beginning meter reading from user

               System.out.print("Please enter the beginning meter reading: ");

               startReading = stdin.nextInt();

               //validating user input

               if(startReading<=0) {

                      System.out.println("I'm sorry, meter readings must be greater than 0.\n");

                      System.out.print("Would you like to enter another reading? : ");

                      cont = stdin.next();

                      if(cont.equals("yes"))

                             continue;

               }

                //Taking input ending meter reading from user

               if(cont.equals("yes")) {

                     System.out.print("Please enter the ending meter reading: ");

                     endReading = stdin.nextInt();

                     //validating user input

                     if(endReading <= startReading) {

                          System.out.println("I'm sorry, the ending meter readings must be greater than starting meter reading.\n");

                          System.out.print("Would you like to enter another reading? : ");

                          cont = stdin.next();

                          if(cont.equals("yes"))

                             continue;

                     }

                }

                if(cont.equals("yes")) {

                     usage = endReading - startReading;        //calculating usage

                     System.out.println("\nThe usage for this period: "+usage+" kWh");

                     //calculating charges based on condition

                     if(month.equals("JULY") || month.equals("AUGUST") || month.equals("SEPTEMBER") ) {

                           if(usage<=100) {

                                 charges = .46*usage;

                                 System.out.println("The charges for this month for 100 kWh at 46 cents per kWh: $"+df.format(charges)+" USD");

                      }

                      else {

                            charges = .46*100 + .52*(usage-100);

                            System.out.println("The charges for this month for 100 kWh at 46 cents/kWh and "+(usage-100)+" kWh overage at 52 cents/kWh: $"+df.format(charges)+" USD");

                      }

                   }

                  else {

                    if(usage<=100) {

                            charges = .42*usage;

                            System.out.println("The charges for this month for 100 kWh at 42 cents per kWh: $"+df.format(charges)+ " USD");

                      }

                      else {

                            charges = .42*100 + .48*(usage-100);

                            System.out.println("The charges for this month for 100 kWh at 42 cents/kWh and "+(usage-100)+" kWh overage at 48 cents/kWh: $"+df.format(charges)+" USD");

                     }

                  }   

                     

             

                totalUsage = totalUsage + usage;             //calculating total usage

                totalCharges = totalCharges + charges;     //calculating total cjatges

                count++;                                 //counter value to keep track of number of bill input

                flag=1;

                System.out.print("\nWould you like to enter another reading? : ");

                cont = stdin.next();

             }       

               

         }while(cont.equals("yes"));

        

         //Printing total bill details of all months

         if(flag==1) {    

               avergeUsage = totalUsage/count;

               averageCharge = totalCharges/count;

               System.out.print("\nTotal Usage: "+ totalUsage+" kWh.");

               System.out.print(" Total charges for the "+count+" months of readings: $"+ df.format(totalCharges));

               System.out.print(" Your average usage is "+avergeUsage+" kWh, ");

               System.out.println("and your average charge is $"+df.format(averageCharge)+" per month");

        }

     }        

}

  

Please enter the month for the reading April Please enter the beginning meter reading: -100 Im sorry meter readings must be greater than 0 Would you like to enter another reading? yes Please enter the month for the reading April Please enter the beginning meter reading: 200 Please enter the ending meter reading: 100 Im sorry the ending meter readings must be greater than starting meter reading Would you like to enter another reading? yes Please enter the month for the reading May Please enter the beginning meter reading 100 Please enter the ending meter reading: 200 The usage for this period 100 kWh The charges for this month for 100 kWh at 42 cents per kWh: $42.00 USD Would you like to enter another reading? yes Please enter the month for the reading June Please enter the beginning meter reading: 200 Please enter the ending meter reading: 400 The usage for this period: 200 kWh The charges for this month for 100 kWh at 42 cents/kWh and 100 kWh overage at 48 cents/kWh: $90.00 USD Would you like to enter another reading? yes Please enter the month for the reading: July Please enter the beginning meter reading 400 Please enter the ending meter reading: 750 The usage for this period: 350 kWh The charges for this month for 100 kWh at 46 cents/kWh and 250 kWh overage at 52 cents/kWh: $176.00 USD Would you like to enter another reading? no Total Usage: 650 kWh. Total charges for the 3 months of readings: $308.00 Your a verage usage is 216 kWh. and your average charge is $102.67 per month

Add a comment
Know the answer?
Add Answer to:
JAVA *REFER TO THE PICTURES* Summary Write a program that will calculate the monthly electric charges...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • computer programming Write a C program that will calculate and print monthly water bills. The total...

    computer programming Write a C program that will calculate and print monthly water bills. The total units consumed per month are derived from subtracting the previous meter readings with the current meter reading. The charges are calculated based on the rates stated in Table 2. The sample output is shown in Figure 16 Tulis aturcara Cyang akan mengira dan mencetak bil air bulanan Jumlah unit yang diguna sebulan dikira dengan menolak bacaan meter sebelum dengan bacaan meter terkinl. Caj dikira...

  • The electric company charges according to the following rate schedule: 9 cents per kilowatt-hour (kwh) for...

    The electric company charges according to the following rate schedule: 9 cents per kilowatt-hour (kwh) for the first 300 kwh 8 cents per kwh for the next 300 kwh (up to 600 kwh) 6 cents per kwh for the next 400 kwh (up to 1000 kwh) 5 cents per kwh for all electricity used over 1000 kwh Write a program that would repeatedly read in a customer number (an integer) and the usage for that customer in kwh (an integer)....

  • I submited this question before but they didnt follow the requirements/contraints or format...they didnt use methods....

    I submited this question before but they didnt follow the requirements/contraints or format...they didnt use methods. Please use comments. Write  a JAVA program that will ask for the customer’s last and current meter reading in Kilowatt Hours (KwHs). Determine the amount of usage for the month and calculate a subtotal (before tax) and a total amount due (tax included) using the following constraints. Constraints Rate A: For 500 KwHs or less = $0.0809 / KwH Rate B: For 501 to 900...

  • Write a program in c++ for An electric company came out with a residential rate schedule...

    Write a program in c++ for An electric company came out with a residential rate schedule in your state. You are asked to write a program that will compute the customer’s electric bill. Program will prompt month number and Kilowatt hour used. Sample Input Screen:             Enter the month (1 - 12)                      :             Kilowatt hours used                             : The electric bill is computed using the following method: There is a flat service charge of $15.31...

  • write a program in java that determines the change to be dispensed from a vending machine....

    write a program in java that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 cents and a dollar, in a 5-cent increments(25,30,35.....,90,95,or 100), and the machine accepts only a single dollar bill to pay for the item. for example a possible dialogue with the user might be "Enter price of item (from 25 cents to a dollar, in 5-cent increments):45 you boughtan item for 45 cents and gave me...

  • Q2.1) Write a program to calculate phone bill of the user. The rule to calculate bill...

    Q2.1) Write a program to calculate phone bill of the user. The rule to calculate bill is given as follows: • You should ask the option to the user at first. If the phone bill will be calculated with internet connection option, user must enter 1, otherwise user must enter O. Do all necessary controls and take the number from the user until the user enters one of the correct options. (1 or 0). • Design 2 different methods. Both...

  • ***** JAVA ONLY ***** Write a program that uses nested loops to collect data and calculate...

    ***** JAVA ONLY ***** Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. Frist the program should ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the...

  • JAVA Programming . Description: For an unknown number of employees: prompt and receive payroll data; calculate...

    JAVA Programming . Description: For an unknown number of employees: prompt and receive payroll data; calculate gross pay, taxes owed, and net pay; and display a pay stub. Input : Prompt and receive input from the user for the following:  /// Employee’s First and Last Name  /// Hours Worked  /// Pay Rate  /// Overtime Rate Multiplier ** For the Employee’s First and Last Name:  Both data items must be read in one prompting into one...

  • Using Python write a code for Function 1: A bank charges $10 per month plus the...

    Using Python write a code for Function 1: A bank charges $10 per month plus the following check fees for a commercial checking account: a. $0.10 each for 1-19 checks b. $0.08 each for 20-39 checks c. $0.06 each for 40-59 checks d. $0.04 each for 60 or more checks. (Note that the same fee is charged for all checks. If the customer writes 21 checks, all 21 checks are billed at the $0.08 rate.) The bank also charges an...

  • Write a complete C++ program that creates a monthly bill for the text messaging. Your cell...

    Write a complete C++ program that creates a monthly bill for the text messaging. Your cell phone company provides the following three text messaging plans. Package A: Two Thumbs.   For $9.95 per month, 100 text messages are allowed. Additional text messages are 15 cents each. Package B: All Thumbs. For $14.95 per month, 200 text messages are allowed. Additional text messages are 10 cents each. Package C: Lightning Thumbs. For $19.95 per month, unlimited text messaging is provided. State sales...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT