Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I submitted my main class & subclass in Java, my teacher gave me some feedback but i'm not sure how to declare the tax rate

I submitted my main class & subclass in Java, my teacher gave me some feedback but i'm not sure how to declare the tax rate in just the subclass & re use it in main. Also how would I use the local variables from subclass. This is what my teacheres feedback was: (I did fix some of the required changes already)

This method name needs to be changed from: getsubtotal to: getSubtotal. You have a few in the subclass like this. Rates should have an underscore. Example, this: RATEA should be this: RATE_A You have the tax rate declared in main and in the subclass. It needs only to be declared in the subclass. You should find a way to use local variables in the subclass methods. Then send the results onto the next method. Any usage uses the Rate A rate. That should be fixed.?

?MY MAIN CLASS:

//Begin Main Method public static void main(String[] args) {

Subclass MyUtility = new Subclass(); //Gives access to subclass

String choice; //Set variable for loop that allows user to rerun

do { //Loop gets readings from customer System.out.println("Welcome to the City Power Bill Calculator!");

Scanner input = new Scanner(System.in);

System.out.print("Please enter your previous meter reading:"); double preread = input.nextDouble(); //Users first input

System.out.print("Please enter your current reading:"); double curread = input.nextDouble(); //Users second input

System.out.printf("Your usage was %.1f KhWs ", MyUtility.getUsage(curread, preread)); //Call getusage

//Assign usage to the variable "total" to determine rate double total = MyUtility.getUsage(curread, preread);

System.out.printf("Your rate was $%.4f/KhWs ", MyUtility.getRate()); //Return rate

double rate = MyUtility.getRate(); //Assign rate to variable

System.out.printf("Your subtotal is $%.2f ", MyUtility.getSubtotal(total, rate)); //Call getsubtotal

double subtotal = MyUtility.getSubtotal(total, rate); //Assign subtotal final double TAXPERCENT = 0.0346; //Assign tax percent

System.out.printf("Your tax was $%.2f ", MyUtility.getTax(subtotal, TAXPERCENT));//Call gettax double tax = MyUtility.getTax(subtotal, TAXPERCENT); //Assign tax double totalbill = (subtotal + tax); //Assign bill total

System.out.printf("Your total bill this month is $%.2f ", totalbill); //Return the over all bill amount

System.out.println("Would you like to run again? y or n"); choice = input.next(); //User can rerun program or not

} while (choice.equalsIgnoreCase("y")); //Reruns program

System.out.println("Thank you for " + "using the program! Goodbye"); //Ends program }

Subclass

//Set variables for subclass private final double RATE_A = 0.0809; private final double RATE_B = 0.091; private final double RATE_C = 0.109; private double rate; private double tax; private double total; private double subtotal; private double finalBill; public final double TAXPERCENT = 0.0346;

//Set public variables to call to methods public Subclass() { this(0,0); } /** * * @param curread * @param preread */ public Subclass(double curread, double preread) { total = curread - preread; setRate(total); //Determines the users usage and sets it to setRate }

/** * * @return */ public double getRate() { //Return users rate return rate; }

/** * * @param total */ private void setRate(double total) { //Calculate rate for customers bill if (total <= 500) { rate = RATE_A; } else if (total > 500 && total <= 900) { rate = RATE_B; } else { rate = RATE_C; } setSubtotal(); }

/** * * @param subtot * @param tot * @return */ public static final double getTax(double subtot, double tot) { double tax; tax = (subtot * tot); return tax; //Return users tax amount

}

/** * */ public void setTax() { //Calculates the users tax tax = subtotal * TAXPERCENT; }

/** * * @param current * @param previous * @return */ public static double getUsage(double current, double previous) { double total; total = (current - previous); return total; //Calculate rate, subtotal, tax, & total for users bill }

/** * * @param usage */ public void setUsage(double usage) { this.total = usage; //Returns the usage total for customers bill }

/** * * @param usage * @param rating * @return */ public static double getSubtotal(double usage, double rating) { double subtotal; subtotal = (usage * rating); return subtotal; //Returns users subtotal } private void setSubtotal() { //Calculates subtotal for customers bill subtotal = total * rate; setFinalBill(); }

public double getFinalBill() { //Returns final bill amount return finalBill; } private void setFinalBill() { //Calculates the final bill amount finalBill = subtotal + tax; }

}

So what I need help with is making sure the tax rate 0.0346 is only declared in the subclass and in working function for mainclass. I also need to find a way to use local variables in the subclass methods. Then send the results onto the next method. Any usage uses the Rate A rate. That should be fixed.?

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 Databases 11th British National Conference On Databases Bncod 11 Keele Uk July 7 9 1993 Proceedings Lncs 696

Authors: Michael F. Worboys ,Anna F. Grundy

1993rd Edition

3540569219, 978-3540569213

More Books

Students also viewed these Databases questions

Question

Please solve this question

Answered: 1 week ago

Question

5. List the forces that shape a groups decisions

Answered: 1 week ago

Question

4. Identify how culture affects appropriate leadership behavior

Answered: 1 week ago