1. Member
Join Date
Dec 2013
Posts
3
Rep Power
0

## 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;
}
public double computeBill(int price, int q)
{
bookPrice = price;
quantity = q;
total = (price * q) * tax;
}
public double computeBill(int price, int q, int c)
{
bookPrice = price;
quantity = q;
coupon = c;
total = (price * q) - c * tax;
}
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();
}
}
Last edited by bullet; 12-10-2013 at 12:45 AM. Reason: code

2. ## Re: billing help?

What's your question? You say you need help, but with what? Where are you stuck? What are you confused about?

3. Member
Join Date
Dec 2013
Posts
3
Rep Power
0

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

4. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

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

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

Java Code:
`public int computeBill(int price, int q, int c) {`
See? The compiler is telling the truth. It always does.

5. Member
Join Date
Dec 2013
Posts
3
Rep Power
0

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

6. Senior Member
Join Date
Apr 2013
Location
Sweden
Posts
272
Rep Power
4

## Re: billing help?

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.

7. ## Re: billing help?

Java 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.
Last edited by jbarke12; 12-10-2013 at 07:04 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•