Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming Lab Need help desparately! You can help me graduate! You are at

ID: 3556908 • Letter: J

Question

Java Programming Lab

Need help desparately! You can help me graduate!

You are at a rodeo with a group of friends. Before it begins, you and your friends decide to get
snacks. The menu items sold at the snack bar along with their prices are displayed below. Your
task is to write a program that displays a menu. The snack bar sells six different items. Sandwich,
chips, brownie, regular drink, large drink, and pickle. The program should repeatedly display the
menu below until the sale is totaled. The program should keep a running total of the amount of
each item purchased, and this total should be displayed on the screen each time the menu is
displayed. If at any time, someone cancels the order, clear your running total and display the
menu again. When the sale is totaled, calculate the sales tax. (Use 8%) Print the final amount due
on the screen.

Declare the price for each item as a constant.

Here is what the menu should look like:

ITEMS PRICE
S - Sandwich $2.00
C - Chips $0.50
B - Brownie $1.00
R - Regular Drink $1.00
L - Large Drink $1.50
P - Pickle $0.75
X - Cancel the order
T - Total the sale

Your total order is: $4.33

Explanation / Answer

import java.util.Scanner;

class snackMenu
{
   public static void printMenu()
   {
       System.out.println(" ITEMS PRICE");
       System.out.println("S - Sandwich $2.00");
       System.out.println("C - Chips $0.50");
       System.out.println("B - Brownie $1.00");
       System.out.println("R - Regular Drink $1.00");
       System.out.println("L - Large Drink $1.50");
       System.out.println("P - Pickle $0.75");
       System.out.println("X - Cancel the order");
       System.out.println("T - Total the sale");
   }

   public static String getOrder()
   {
       String ans;
       Scanner input = new Scanner(System.in);
       System.out.print("Please enter choice: ");
       ans = input.nextLine();

       return ans;
   }

   public static void main(String args[])
   {
       String ans;
       double total = 0.0;

       printMenu();

       do
       {
           ans = getOrder();
           if (ans.equalsIgnoreCase("S"))
               total = total + 2.0;
           else if (ans.equalsIgnoreCase("C"))
               total = total + 0.5;
           else if (ans.equalsIgnoreCase("B"))
               total = total + 1.0;
           else if (ans.equalsIgnoreCase("R"))
               total = total + 1.0;
           else if (ans.equalsIgnoreCase("L"))
               total = total + 1.5;
           else if (ans.equalsIgnoreCase("P"))
               total = total + 0.75;
           else if (ans.equalsIgnoreCase("X"))
           {
               total = 0.0;
               break;
           }
           else if (ans.equalsIgnoreCase("T"))
           {
               System.out.print("Your total order is: $" + total);
               break;
           }

       } while ((!ans.equalsIgnoreCase("X")) && (!ans.equalsIgnoreCase("T")));

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote