Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: need help with java progra,

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question need help with java progra,

    i am trying to do this program. it compiles and everything but the numbers are not coming out right. any help would be greatly appreciated.
    thank you

    heres the problem.

    Write a program that computes the tax and tip on a restaurant
    bill. The program should use JOptionPane to ask the user to enter the
    charge for the meal. The tax should be 6.75 percent of the meal
    charge. The tip should be 15 percent of the total after adding the
    tax. Display the meal charge, tax amount, tip amount, and total bill
    on the screen.



    import javax.swing.JOptionPane;

    public class Bill
    {
    public static void main(String[] args)
    {
    double mealPurchase = 0;

    mealPurchase = Double.parseDouble(JOptionPane.showInputDialog(nul l, " Enter meal total: "));

    double mealTax = 0.0675;

    double mealTip = 0.15;

    double mealSubtotal = mealPurchase * mealTax;

    double plusTip = mealPurchase * mealTip + mealSubtotal;

    double mealTotal = plusTip + mealSubtotal;

    JOptionPane.showMessageDialog(null, " Meal charge: " + mealPurchase +
    "\nTax Amount: " + mealSubtotal +
    "\nTip Amount: " + plusTip +
    "\nMeal Total: " + mealTotal );

    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,136
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: need help with java progra,

    the numbers are not coming out right.
    Please post the program's current output and add some comments showing what it should be. If needed, add a call to System.out.println() to show the output for copying here.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: need help with java progra,

    sorry.
    i am trying to calculate the tax and tip and then show the total amount on a dialog box.
    this is what i get when i run it entering 10.00 dollar meal purchase.

    Meal charge: 10
    Sales Tax: 0.0675 ( i need it to calculate the sales tax from the 10 dollars that i enter, but instaed it tells me the amount of the sales tax.
    Tip Amount: 2.175 ( i need the tip amount after i add the meal charge and sales tax
    Meal Total: 2.8499999 ( here i need the added amount of meal purchase + sales tax + tip amount)


    i am not getting the right amount. and it starts with the sales tip since it doesn't calculate anything it just shows the tax that i input

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,136
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: need help with java progra,

    it just shows the tax that i input
    ...
    i am not getting the right amount
    What does the program compute and report when it is executed? If needed, add a call to System.out.println() to show the output for copying here.

    If you are having problems with any of the equations, add a println() statement after each equation that prints out the value of the results so you can see what each expression is computing.

    Don't forget: Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2014
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: need help with java progra,

    calculation is your problem..
    if im not wrong, if you try to multiply 10 to 0.0675 the answer would become 0.675 instead of 6.75 its because of the one zero added from your mealtax value instead of 0.675
    try to change the value of your mealTax to 0.675, and this will might fix your problem

Similar Threads

  1. Array - Random Numbers Progra, Help
    By Jediknock in forum Collections and Generics
    Replies: 2
    Last Post: March 21st, 2011, 10:13 PM