Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chegg I need your help yet again; this is my last task, and to be honest I'm lost with this whole debugging thing, and I

Chegg I need your help yet again; this is my last task, and to be honest I'm lost with this whole debugging thing, and I need your help. This is a long one, belew is the task for our last week, but don't worry I'm still going to need my Chegg friends for my next class. That said below is the TASK for week 14, and below that are the TASK Requirement for Week 6 Task.

TASK

After downloading the program Week14Debug, load in into NetBeans. The program is based upon your Week 6 Task with exception handling and validation included. The additional pages mentioned in the assignment module are a snapshot of the code as it exists in the download. The purpose of these pages is so you will have a starting point of reference for the line numbers.

Task Requirements

Debug the program by finding all of the errors that are present. Once you have the program debugged and running, make sure your output matches the criteria from the Week 6 Task. Review the Week 6 Task if you need a refresher on the criteria/requirements. The program has syntax and logic errors scattered throughout the Main Class and the Subclass. There are approximately 24 errors that need to be found and corrected.

BELOW ARE THE WEEK 14 CODES THAT NEED TO DEBUGGED

/* SDEV 250 ~ Java Programming I

* Author Name: steven.hickey

* Assignment Name: week14debug

* Date: Oct 1, 2014

* Description: Program with multiple errors for debugging purposes.

Based on Week 6 Assignment

*/

package week14debug;

//Imports

import java.util.InputMismatchException;

//Begin Class Week14Debug

public class Week14Debug {

//Begin Main Method

public static void main(String[] args) {

//New Scanner object

Scanner sc = new Scanner(System);

//Declare variables

int prev, wrg;

String ans = "Y";

boolean flag1 = false, YesNo;

//Ask user for input and receive it

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

//Begin while loop

do {

do { /* Begin internal do loop */

try { /* Try/Catch block beginning */

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

prev = sc.nextInt();

} catch (InputMismatchException IME) {

System.err.printf("Exception: %s ", IME);

errCall(); /* Call error message */

sc.nextLine(); /* Clear buffer */

} /* End Try/Catch block */

} while (flag1); /* End internal do loop */

do { /* Begin internal do loop */

try { /* Try/Catch block beginning */

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

curr = sc.nextInt();

if (prev > curr) { /* Check for previous reading < current reading */

System.out.print("Your current entry must be higher than your previous! ");

flag1 = true;

} else {

}

} catch (InputMismatchException IME) {

System.err.printf("Exception: %s ", IME)

errCall(); /* Call error message */

sc.nextLine(); /* Clear buffer */

flag1 = true;

} /* End Try/Catch block */

} while (flag1); /* End internal do loop */

//New instance of the subclass & set current and previous values

MyCalcs myCalcs = new MyCalcs(prev,wrg);

//Set usage and call it for output

myCalcs.setUsage();

System.out.print("Your usage was: %dKwHs ", myCalcs.getUsage());

//Set rate and call it for output

myCalcs.setRate();

System.out.printf("Your rate is: $%.4f/KwH ", myCalcs.getRate());

//Set subtotal and call it for output

myCalcs.setSubTot();

System.out.printf("Your Subtotal will be: $%.2f ", myCalcs.getSubTot();

//Set taxes and call them for output

myCalcs.setTax();

System.out.printf("Your taxes are: $%.2d ", myCalcs.getTax());

//Set total bill and call it for output

myCalcs.setTot();

System.out.printf("Your total bill this month is: $%.2f ", myCalcs.setTot());

//Run again? Validate answer. Begin inner loop.

do {

System.out.print("Calculate a new usage? Y for Yes, N for No: ");

ans = sc.next();

if (!(ans.equals("Y") || ans.equals("N"))) {

YesNo = true; /* reset incase of previous good run */

System.err.println("Exception! Please enter only a Y for Yes or an N for No.");

} else if (ans.equals("Y")) {

YesNo = false;

} else {

System.out.println("Thank you for using the program! Good Bye!");

YesNo = false;

}

} until (YesNo); // End inner loop

} while (ans.equals("Y"));//End outer while loop

} //End Main Method

//Method to output error message

public static void errCall() {

System.err.println("You must enter a numeric value. Please try again. ");

}

} //End Class Week14Debug

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/* SDEV 250 ~ Java Programming I * Author Name: steven.hickey * Assignment Name: week14debug * Date: Oct 1, 2014 * Description: Subclass for debugging exercise Based on Week 6 Assignment

*/ package week14debug;

/* Begin Class MyCalcs */ public class MyCalcs {

/* Variable declarations */ private int prev, curr, use; private final double RATE_A = .0809, RATE_B = .091, RATE_C = .109, TAX_R = .0346; private double rate, sub, tax, tot;

/* Constructor initializes default set in main class. */ MyCalcs(int prv, int cur) { prev = prv; curr = cur; }

/* Set methods*************************************************************/ /* Set usage */ public void setUsage() { use = prev - curr; }

/* Set rate */ public void setRate() { if (use <= 500) { rate = RATE_A; } else if (use > 500 || use > 900) { rate = RATE_B; } else { rate = RATE_C; } }

/* Set subtotal */ public void setSubTot() { sub = use * rate; }

/* Set taxes */ public void setTax() { tax = sub / TAX_R; }

/* Set total bill */ public void setTot() { tot = tax - sub; }

/* Get methods*************************************************************/ /* Get Usage */ public void getUsage() { use = use; }

/* Get rate */ public double getRate() { return sub; }

/* Get subtotal */ public double getSubTot() { return rate; }

/* et taxes */ public double getTax() { return tax; }

/* Get total */ public double getTot() { return tot; }

} /* End Class MyCalcs */

BELOW IS THE WEEK 6 TASK WITH EXPECTED OUTPUT IN BOLD.

Write a program that asks for the customers last and current meter reading in Kilowatt Hours (KwHs). Determine the amount of usage for the month and calculate a sub total (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

Use a method to determine the usage

Use a second method to determine the tax

Use a third method to determine the subtotal

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

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

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!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions

Question

Answered: 1 week ago

Answered: 1 week ago