Question

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 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 red.

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

Please enter your previous meter reading: 750
Please enter your current meter reading: 1350.63

Your usage was: 600.6 KwHs
Your rate was: $0.0910/KwH
Your subtotal is: $54.66
Taxes are: $1.89
Your total bill this month is: $56.55

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

Please enter your previous meter reading: 750.39

Please enter your current meter reading: 1655.37

Your usage was: 905.0 KwHs
Your rate was: $0.1090/KwH
Your subtotal is: $98.64 Taxes are: $3.41
Your total bill this month is: $102.06

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

Thank you for using this program. Goodbye!

Deliverables

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

Main.java

import java.util.Scanner;

class Main

{

public static void main (String[] args){

Scanner input=new Scanner(System.in);

MyUtility utility=new MyUtility();

utility.setUtilityTaxPercent(3.46);

double prvsReading, currentReading;

String response;

System.out.println("Welcome to the City Power Bill Calculator!");

while(true){

System.out.print("Please enter your previous meter reading:");

prvsReading=Double. parseDouble(input.nextLine());

System.out.print("Please enter your current meter reading:");

currentReading=Double. parseDouble(input.nextLine());

  

utility.setPreviousReading(prvsReading);

utility.setCurrentReading(currentReading );

System.out.println(String.format("Your usage was: %.1f KwHs",utility.getUsage()));

System.out.println(String.format("Your rate was: $%.4f/KwHs",utility.getRate()));

System.out.println(String.format("Your subtotal is: $%.2f",utility.getSubtotal()));

System.out.println(String.format("Taxes are: $%.2f",utility.getTax()));

System.out.println(String.format("Your total bill this month is: $%.2f",utility.getTotalBill()));

System.out.print("Would you like to calculate a new usage?\n"+

"(Y for Yes, N to exit):" );

response=input.nextLine();

if(response.equals("n")||response.equals("N"))

break;

  

}

System.out.println("Thank you for using this program. Goodbye!");

}

}

class MyUtility{

private double prvsReading;

private double currentReading;

private double utilityTaxPercent;

MyUtility(){

prvsReading=0;

currentReading=0;

utilityTaxPercent=0;

}

MyUtility(double prvs,double curr){

prvsReading=prvs;

currentReading=curr;

utilityTaxPercent=3.46;

}

public double getPreviousReading(){

return prvsReading;

}

public double getCurrentReading(){

return currentReading;

}

public void setPreviousReading(double prvs){

prvsReading=prvs;

}

public void setCurrentReading(double curr){

currentReading=curr;

}

public double getUtilityTaxPercent(){

return utilityTaxPercent;

}

public void setUtilityTaxPercent(double tax){

utilityTaxPercent=tax;

}

public double getUsage(){

return currentReading-prvsReading;

}

public double getRate(){

double usage=getUsage();

if(usage<=500)

return 0.0809;

else if(usage>500&&usage<=900)

return 0.091;

else

return 0.109;

}

public double getSubtotal(){

return getUsage()*getRate();

}

public double getTax(){

return (getSubtotal()*getUtilityTaxPercent())/100;

}

public double getTotalBill(){

return getSubtotal()+getTax();

}

}

Add a comment
Know the answer?
Add Answer to:
I submited this question before but they didnt follow the requirements/contraints or format...they didnt use methods....
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
  • Flow Measurement Methods Obiective: To demonstrate the use of a Rotameter and obstruction and an ...

    can you please do the analysis for run# 2,3 and 4 Flow Measurement Methods Obiective: To demonstrate the use of a Rotameter and obstruction and an orifice plate meter) for flow rate measurements. Venturi & orifice meter dimensions Venturi meter pipe diameter = 26 mm and throat diameter= 16 mm Orifice meter pipe diameter 51.9 mm and throat diameter-20 mm Open the apparatus valve until the rotameter shows a reading of approximately 10 mm. Record the readings in the following...

  • alue The president's executive jet is not fully utilized. You judge that its use by other...

    alue The president's executive jet is not fully utilized. You judge that its use by other officers would increase direct operating costs by only $36,000 a year and would save $100,000 a year in airline bills. On the other hand, you believe that with the increased use the company will need to replace the jet at the end of three years rather than four. A new jet costs $1.26 million and (at its current low rate of use) has a...

  • Please, I won't get a and b right. Thank you! Problem 6-31 Equivalent annual costs The...

    Please, I won't get a and b right. Thank you! Problem 6-31 Equivalent annual costs The president's executive jet is not fully utilized. You judge that its use by other officers would increase direct operating costs by only $22,000 a year and would save $100,000 a year in airline bills. On the other hand, you believe that with the increased use the company will need to replace the jet at the end of three years rather than four. A new...

  • The president's executive jet is not fully utilized. You judge that its use by other officers...

    The president's executive jet is not fully utilized. You judge that its use by other officers would increase direct operating costs by only $21,000 a year and would save $100,000 a year in airline bills. On the other hand, you believe that with the increased use the company will need to replace the jet at the end of three years rather than four. A new jet costs $1.18 million and (at its current low rate of use) has a life...

  • My Java code from last assignment: Previous Java code: public static void main(String args[]) { //...

    My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...

  • I need help completing all of part B please Check mywrk Exercise 9-11A Calculating employee and...

    I need help completing all of part B please Check mywrk Exercise 9-11A Calculating employee and employer payroll taxes LO 9-5 3.57 Sky Co. employed Tom Mills in Year 1. Tom earned $5,100 per month and worked the entire year. Assume the Social Security tax rate is 6 percent for the first $110,000 of earnings, and the Medicare tax rate is 1.5 percent. Tom's federal income tax withholding amount is $910 per month. Use 5.4 percent for the state unemployment...

  • please use the information from questions 3, 4, and 5 to answer question 6 Question 3...

    please use the information from questions 3, 4, and 5 to answer question 6 Question 3 0.3 pts As described above, the country of Irvineland has an income tax rate of 30% on the first $30,000 of taxable income, 40% on the next $30,000 in taxable income, and 50% on all taxable income above $60,000. Irvineland allows a standard deduction of $12,000 for single taxfilers. Zed Zot has gross income of $70,000. As a single person, he takes a standard...

  • Could someone please help me? I am confused. Saved Built Problems Required information The following information...

    Could someone please help me? I am confused. Saved Built Problems Required information The following information applies to the questions displayed below.) Laker Company reported the following January purchases and sales data for its only product. Units sold at Retail Units Acquired at Cost 195 units $12.00 – $2,340 155 units @ $21.00 Date Activities Jan. 1 Beginning inventory Jan. 10 Sales Jan. 20 Purchase Jan. 25 Sales Jan. 30 Purchase Totals 135 units @ $21.00 120 units@ $11.00 =...

  • JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole...

    JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole I would like it to print the first 3 payments and the last 3 payments if n is larger than 6 payments. Please help! Thank you!! //start of program import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.lang.Math; //345678901234567890123456789012345678901234567890123456789012345678901234567890 /** * Write a description of class MortgageCalculator here. * * @author () * @version () */ public class LoanAmortization {    /* *...

  • My Java code from last assignment: Previous Java code: public static void main(String args[]) { //...

    My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...

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
ADVERTISEMENT