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

Write a program in JAVA that will ask for the customer’s last and current meter

ID: 3857591 • Letter: W

Question

Write a program in JAVA 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 KwHs = $0.091 / KwH

Rate C: For greater than 900 KwHs = $0.109 / KwH

Utilities Tax is 3.46% regardless of usage.

Requirements

Create a separate (external to the main class) subclass MyUtility()

Rate and tax variables should be private to the subclass

Use a constructor to initialize the default reading values to 0

Use another constructor to set the reading values

Use set and get methods in MyUtility() to determine the usage, rate, subtotal, tax, and final bill

Format all output as follows:

o Usage to 1 decimal place, KhWs
o Rate to 4 decimal places, monetary
o Subtotal to 2 decimal places, monetary o Taxes to 2 decimal places, monetary
o Total to 2 decimal places, monetary

Implement a loop to return and enter new values (run the program again) if the user wishes to Hints

Set methods can do all the computation

Set methods can call other set methods

The type of loop can be of your choosing

Make sure you use Java coding conventions

Expected Output

Below is a sample run with three iterations. User input is in bold.

Welcome to the City Power Bill Calculator!
Please enter your previous meter reading: 750
Please enter your current meter reading: 1250

Your usage was: 500.0 KwHs
Your rate was: $0.0809/KwH
Your subtotal is: $40.45
Taxes are: $1.40
Your total bill this month is: $41.85

Would you like to calculate a new usage?
(Y for Yes, N to exit): y

Explanation / Answer

import java.util.Scanner;
public class HelloWorld
{
public static void main(String []args)
{ int pr,cr,diff;
double ta,bi,total,m,ut;
ta=0.0;
bi=0.0;
total=0.0;
m=0.0;
char ch;
Scanner sc=new Scanner(System.in);
do
{
System.out.println("Welcome to the City Power Bill Calculator!");
System.out.println("Please enter your previous meter reading: ");
pr=sc.nextInt();
System.out.println("Please enter your current meter reading: ");
cr=sc.nextInt();
diff=cr-pr;
ut=3.46/100;
if(diff<=500)
m=0.0809;
else if(diff>=501 && diff<=900)
m=0.091;
else
m=0.109;
System.out.println("Your usage was: "+diff+" KwHs");
System.out.println("Your rate was: $"+m+"/KwH");
bi=diff*m;
System.out.println("Your subtotal is: $"+bi);
ta=ut*bi;
System.out.println("Taxes are: $"+ta);
total=bi+ta;
System.out.println("Your total bill this month is: $"+total);
System.out.println("Would you like to calculate a new usage?");
ch=sc.next().charAt(0);
}while(ch=='y' || ch=='Y');
}
}

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