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!