# billing help?

Printable View

• 12-09-2013, 11:12 PM
bullet
billing help?
i need help community. i need to create a class named billing that includes three overloaded computebill() methods for a photo book store. when computebill() receives a single parameter, it represents the price of one photo book ordered. add 8% tax, and return the total due.
when computebill receives two parameters, they represent the price of a photo book and the quantity ordered. multiply the two values, add 8% tax, and return total.
then when computebill receives three parameters, they represent the price of a book, quantity, and a coupon value. multiply quantity and price, reduce result by coupon value, and then add 8% tax and return total.
then write a main method that tests all methods.
heres my code so far

import java.util.*;
public class Billing
{
double tax = .08;
int coupon = 5;
int bookPrice = 10;
int quantity;
double total;
public double computeBill(int price)
{
bookPrice = price;
total = price * tax;
return total;
}
public double computeBill(int price, int q)
{
bookPrice = price;
quantity = q;
total = (price * q) * tax;
return total;
}
public double computeBill(int price, int q, int c)
{
bookPrice = price;
quantity = q;
coupon = c;
total = (price * q) - c * tax;
return total;
}
public void display()
{
System.out.println("Total cost of " + quantity + " photo books with " + coupon + " off is: " + total);
}
public static void main(String[] args)
{
Billing first = new Billing();
Billing second = new Billing();
Billing third = new Billing();
first.display();
second.display();
third.display();
}
}
• 12-09-2013, 11:38 PM
KevinWorkman
Re: billing help?
What's your question? You say you need help, but with what? Where are you stuck? What are you confused about?
• 12-09-2013, 11:58 PM
bullet
Re: billing help?
C:\Users\Bullet\Desktop\Java Programming\Chapter04\StudentFiles\Exercises\Billi ng.java:9: error: invalid method declaration; return type required
public computeBill(int price)
^
C:\Users\Bullet\Desktop\Java Programming\Chapter04\StudentFiles\Exercises\Billi ng.java:15: error: invalid method declaration; return type required
public computeBill(int price, int q)
^
C:\Users\Bullet\Desktop\Java Programming\Chapter04\StudentFiles\Exercises\Billi ng.java:22: error: invalid method declaration; return type required
public computeBill(int price, int q, int c)
^
3 errors
• 12-10-2013, 12:12 AM
gimbal2
Re: billing help?
Try listening to what the compiler is telling you; you have no return types in those methods that it is pointing out to you, its like you've written them half in Java and half in Javascript. If you don't know what a return type is, return to your book and study the chapter on methods again to see how you properly declare them. But because I've already been mistaken for being not nice once before today, I'm just going to show you:

Yours:

Code:

`public computeBill(int price, int q, int c)`
Correct:

Code:

`public int computeBill(int price, int q, int c) {`
See? The compiler is telling the truth. It always does.
• 12-10-2013, 12:46 AM
bullet
Re: billing help?
edited my code, and got rid of errors. but how am i supposed to write a method that tests these methods to see if they actually work correctly?
• 12-10-2013, 12:50 AM
superhaNds
Re: billing help?
Quote:

Originally Posted by bullet
edited my code, and got rid of errors. but how am i supposed to write a method that tests these methods to see if they actually work correctly?

You already have a main method to test the methods.
• 12-10-2013, 07:02 PM
jbarke12
Re: billing help?
However you never call any of your methods in your main method. I would add this instead in the main method

Code:

```Billing test= new Billing(); //testing 1 param //price has to be an int because thats what you defined it as. test.computerBill(30); test.display(); //testing 2 param test.computerBill(30,3); test.display(); //testing 3 param test.computerBill(30,3,2); test.display();```
What you were doing would have given you the same number 3 times. You never used the methods that you created. If you noticed I used the three overloaded methods you created, therefore, each time you should get a different price when you display.