Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The electric company charges according to the following rate schedule: 9 cents p

ID: 3646584 • Letter: T

Question

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). The program should include a method to compute the total charge for each customer. Use the following template for the method: // takes kwh and calculates the total charge for that customer. public static double findCharge(int kwh) { // put your code here } The program should terminate when the user enters a sentinel value of -999 for the customer number. The program should print a three-column chart listing the customer number, the kilowatt-hours used, and the total charge for each customer. The program should also compute and print the number of customers, the total kilowatt-hours used, and the total charges. Use a JTextArea component within a JOptionPane dialog box to display the output. You should name the source code file Hw3.java. Note that you should not use arrays for this assignment.

Explanation / Answer

#include #include #define first .09 /* 9 cents per kwh for first 300 kwh */ #define second .08 /* 8 cents per kwh for next 300 kwh */ #define third .06 /* 6 cents per kwh for next 400 kwh */ #define fourth .05 /* 5 cents per kwh for remaining kwh’s */ /* Ouput Variables */ double cost; double total_cost = 0; int total_customers = 0; int total_kwh = 0; /* Cost Calculating (for kwh) */ double charge_calc_kwh (int *kwhp, int *cust){ if(*kwhp < 300){ cost = ((*kwhp) * (first)); }else if(*kwhp < 600){ cost = (300 * first) + ((*kwhp – 300) * (second)); }else if(*kwhp < 1000){ cost = (300 * first) + ((300) * (second)) + ((*kwhp – 600) * (third)); }else if(*kwhp > 1000){ cost = ((300) * (first)) + ((300) * (second)) + ((400) * (third)) + ((*kwhp – 1000) * (fourth)); } if(*cust && *kwhp != -1){ printf(“ Customer Num: %d”, *cust); printf(” KWH used: %d”, *kwhp); printf(” Charge: %.2f ”, cost); } return(cost); } /* Totaling Values for Final Print */ int totaling(int *kwhp, double *cost){ if(*kwhp != -1){ total_cost += *cost; total_kwh += *kwhp; total_customers = ++total_customers; }else{ printf(“ Total Customers: %d”, total_customers); printf(” Total KWH used %d”, total_kwh); printf(” Total Charges %.2f ”, total_cost); } return(total_cost, total_kwh, total_customers); } int main(void){ /* Input Values */ int kwh; /* kilowatt-hours per customer */ int cust; /* customer number */ while(kwh != -1 && cust != -1){ printf(“Enter customer number and KWH (-1 to quit): “); scanf(“%d %d”, &cust, &kwh); charge_calc_kwh(&kwh, &cust); totaling(&kwh, &cost); } system(“pause”); /* MMMmm windows */ return (0); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote