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.


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

Results 1 to 2 of 2

Thread: Scanner to JOptionPane?

  1. #1
    Junior Member
    Join Date
    Feb 2018
    Thanked 0 Times in 0 Posts

    Default Scanner to JOptionPane?

    Hi all,

    I'm having trouble converting from Scanner to JOptionPane.

    Here is the question:

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

    Here is the code I created using Scanner:

    import java.util.Scanner;

    public class RestaurantBill {

    public static void main( String [ ] args ) {

    //Declare variables
    Scanner scanner = new Scanner( System.in );
    double mealCost; // cost of meal
    double tax; // tax of meal = 0.0675 x cost of meal
    double totalCost; // total cost = meal cost + tax
    double tip; // tip = 0.2 x total cost
    double totalBill; // total of the bill = total cost + tip

    // Prompt user to enter the cost of the meal
    System.out.println( "Please enter the cost of the meal: ");
    mealCost = scanner.nextDouble();

    // Calculate the tax by multiplying 0.0675 x the cost of the meal.
    tax = 0.0675 * mealCost;

    // Calculate the total cost of the meal by adding the meal cost + tax.
    totalCost = mealCost + tax;

    // Calculate the tip by multipling 0.2 x the total cost.
    tip = 0.2 * totalCost;

    // Calculate the total bill by adding the total cost and tip.
    totalBill = totalCost + tip;

    // Display meal cost
    System.out.println("Cost of meal: $" + mealCost );
    // Display tax amount
    System.out.println("Tax: $" + tax );
    // Display tip amount
    System.out.println("Tip: $" + tip );
    // Display total bill
    System.out.println("Total Bill: $" + totalBill );


    I would like to have the pop up window ask the meal cost, and then be able to have 4 more pop up windows that display the meal cost, tax amount, tip amount, and total bill. Thanks so much!

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,705 Times in 2,655 Posts

    Default Re: Scanner to JOptionPane?

    What have you tried?

    Please edit your post and wrap your code with code tags:


    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. JOptionPane help
    By vysero in forum What's Wrong With My Code?
    Replies: 25
    Last Post: September 24th, 2014, 02:54 PM
  2. JOptionPane
    By Kazeth in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 29th, 2014, 11:42 PM
  3. [SOLVED] JOptionPane
    By colognem in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 13th, 2014, 06:45 AM
  4. need help in JOptionPane
    By Zuckerberg in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 28th, 2014, 07:08 AM
  5. JOptionPane using If and Else
    By Liuric in forum Member Introductions
    Replies: 7
    Last Post: October 1st, 2010, 12:05 AM

Tags for this Thread