Results 1 to 7 of 7

Thread: billing help?

  1. #1
    bullet is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default 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();
    }
    }
    Last edited by bullet; 12-09-2013 at 11:45 PM. Reason: code

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,834
    Rep Power
    8

    Default Re: billing help?

    What's your question? You say you need help, but with what? Where are you stuck? What are you confused about?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    bullet is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default 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. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,581
    Rep Power
    5

    Default 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.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    bullet is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default 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. #6
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    262
    Rep Power
    2

    Default Re: billing help?

    Quote Originally Posted by bullet View Post
    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. #7
    jbarke12 is offline Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    79
    Rep Power
    0

    Default Re: billing help?

    However you never call any of your methods in your main method. I would add this instead in the main method

    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 06:04 PM.

Similar Threads

  1. Step-by-Step Billing system in Web Services
    By oneofthelions in forum Web Frameworks
    Replies: 2
    Last Post: 12-18-2009, 10:28 AM

Posting Permissions

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