Question: I am missing headers on my methods somewhere. And my teacher informed me that I'm calling get methods and sending information to them, & that
I am missing headers on my methods somewhere. And my teacher informed me that I'm calling get methods and sending information to them, & that I should not send data to get methods. They should look like my getFinalBill() method... Can anyone help me out?!
?MAIN CLASS:
public static void main(String[] args) { 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 Subclass MyUtility = new Subclass(curread, preread); //Access subclass 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 double TAXPERCENT = MyUtility.getTaxper();
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 }//End Main Method }
?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; }
} //End Subclass Subclass
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
