Results 1 to 15 of 15
  1. #1
    614648637 is offline Member
    Join Date
    Mar 2013
    Posts
    7
    Rep Power
    0

    Post The class is BookCost.Java

    this project is called BookCost
    i have already done a part of it, but it won't compile, i dont know why it won't compile.
    It says that the highlighted part can not be double.

    can anybody gives me some suggestions plz?
    thank you and have a great day

    Here is my problem here:
    Java help please-qq-20130316213156.png

    And here is my source code with some problem.


    import java.util.Scanner;
    public class BookCost
    {
    public static final double BP_PRIZE = 18.95;
    public static final double NB_PRIZE = 21.95;
    public static double getOrderTotal(int bp, int nb)
    {
    int amount;
    double total;
    amount = bp + nb;
    if ( amount >= 12)
    {
    total = 14.00 * ( bp + nb);
    return total;
    }
    else if ( amount <= 12 && amount >= 3)
    {
    total = 15.95 * ( bp + nb);
    return total;
    }
    else if ( bp == 1 && nb == 1)
    {
    total = 37.95;
    return total;
    }
    else if ( bp + nb < 3)
    {
    total = (bp * BP_PRIZE) + (nb * NB_PRIZE);
    return total;
    }
    }


    public static void main (String[] args)
    {
    double total;
    double bp;
    double nb;
    int bpint;
    int nbint;
    Scanner kb = new Scanner (System.in);
    System.out.println("Welcome to Hans's book calculating program!");
    System.out.println("This program is designed for managing how"
    + "\n much does it cost for the user's order.");
    System.out.println("Now please enter the number of <Be Prepared> books you want to order!");
    bpint = kb.nextInt();
    bp = (int)(bpint + 0.5);
    kb.nextLine();
    System.out.println("I got the number sir!");
    System.out.println("Now please enter the number of <Next Bes> books you want to order!");
    nbint = kb.nextInt();
    nb = (int)(nbint + 0.5);
    kb.nextLine();
    System.out.printf("Your prize is" + getOrderTotal(total));
    }
    }
    Last edited by 614648637; 03-17-2013 at 04:39 AM. Reason: Change it to the right course

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Java help please

    Please go through the Forum Rules, particlarly the third paragraph. Then go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly. To change the subject line, click 'Edit Post' and then 'Go Advanced'

    Quote Originally Posted by 614648637 View Post
    i have already done a part of it, but i didn't work at all.
    Assuming that was meant to be "it didn't work at all" you need to be much more specific. What exactly is the problem?
    -- doesn't compile --> paste the compile time errors here
    -- runs but errors out --> paste the stack trace
    -- runs without error, but without the expected result --> post the expected and erroneous results
    -- computer goes up in a puff of green smoke --> disconnect from the internet and run for the trees

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    614648637 is offline Member
    Join Date
    Mar 2013
    Posts
    7
    Rep Power
    0

    Default Re: Java help please

    Good now?

  4. #4
    SJF
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Posts
    108
    Rep Power
    0

    Default Re: Java help please

    System.out.printf("Your prize is %f\n", getOrderTotal(total));

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java help please

    Quote Originally Posted by SJF View Post
    System.out.printf("Your prize is %f\n", getOrderTotal(total));
    Did you try it? I can see an getOrderTotal( ... ) method that takes two int parameters but I can't find one that takes one double parameter ...
    Your reply doesn't answer nor solver anything at all.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    614648637 is offline Member
    Join Date
    Mar 2013
    Posts
    7
    Rep Power
    0

    Default Re: Java help please

    Java help please-qq-20130317080730.png
    not it still have the same problem.
    It says that: can not use Bookcost's getordertotal for double

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java help please

    What are the parameter types of the getOrderTotal( ... ) method? What's the type of the single parameter you're trying to pass?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    614648637 is offline Member
    Join Date
    Mar 2013
    Posts
    7
    Rep Power
    0

    Default Re: Java help please

    Here is my parameter types:
    i use double for getOrderTotal
    Java help please-qq-20130317090419.png

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java help please

    Quote Originally Posted by 614648637 View Post
    Here is my parameter types:
    i use double for getOrderTotal
    Which is dead wrong because the method (you wrote it yourself did you?) expects to int parameters.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    614648637 is offline Member
    Join Date
    Mar 2013
    Posts
    7
    Rep Power
    0

    Default Re: Java help please

    But my text book says that i got to do like that.
    look at the stuff i posted on at first.

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java help please

    Quote Originally Posted by 614648637 View Post
    But my text book says that i got to do like that.
    look at the stuff i posted on at first.
    Also in your first post I see a method that takes two int parameters and your assignment text wants it that way.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    614648637 is offline Member
    Join Date
    Mar 2013
    Posts
    7
    Rep Power
    0

    Default Re: Java help please

    yeah, i know, but the what this program needs to do is to calculate out the total money.
    so i got to return only one number to main.
    so can u just correct me out which part i do wrong, thanks

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java help please

    Quote Originally Posted by 614648637 View Post
    yeah, i know, but the what this program needs to do is to calculate out the total money.
    so i got to return only one number to main.
    so can u just correct me out which part i do wrong, thanks
    I told you several times already: your method expects two int parameters but you're supplying only one double parameter; your compiler doesn't like that.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    614648637 is offline Member
    Join Date
    Mar 2013
    Posts
    7
    Rep Power
    0

    Default Re: Java help please

    so what should i write like?

  15. #15
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java help please

    Quote Originally Posted by 614648637 View Post
    so what should i write like?
    According to your assignment text you should leave the method signature as it is so you should pass two int parameters.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Tags for this Thread

Posting Permissions

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