'I want to add 10% service tax and 13% vat but I am unable to do

Here is my homework:

You are required to create an MVP (Minimal Viable Product) to take customer orders for a local ethnic food restaurant in Kathmandu. The restaurant offers 10 different types of food dishes, taken from the local ethnic food culture. The restaurant operates with limited dishes and limited staff. You are required to create a prototype of order taking system to ease the working process within the restaurant. Your program should have the following functionalities:

  • The program should display the menu at the start (with 10 dishes)
  • Each customer will make an order based on the menu shown. For each order, the system should calculate the total bill.
  • For each bill, after adding the sum total of the prices of the dishes, the sum total would be subject to 10% service Tax and 13% VAT.
  • For every new instance where a customer (new or repeating) makes an order, a new bill is generated.
  • Altering a confirmed order would not be a necessary feature for the MVP phase of the system.
  • Your MVP should be able to manage order and billing of 5 customers at once.
  • The menu prices and the dishes in them could be initially hardwired into your MVP for test purposes (in a file or an array)

My code:

public class Array { //class name

    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        int choice;
        double total = 0;
        double tax = 0.10;

        //Array for storing prices
        double[] Price = new double[10];
        Price[0] = 120;
        Price[1] = 80;
        Price[2] = 40;
        Price[3] = 100;
        Price[4] = 50;
        Price[5] = 60;
        Price[6] = 90;
        Price[7] = 45;
        Price[8] = 70;
        Price[9] = 60;

        //Menu item array
        String[] FoodItem = new String[10];
        FoodItem[0] = "Momo";
        FoodItem[1] = "Chawmin";
        FoodItem[2] = "Sausages";
        FoodItem[3] = "Pizza";
        FoodItem[4] = "Burger";
        FoodItem[5] = "Buff Sekuwa";
        FoodItem[6] = "Chicken Sekuwa";
        FoodItem[7] = "Alu Paratha";
        FoodItem[8] = "Chicken Chilly";
        FoodItem[9] = "Fry Rice";

        //Welcome user and gather their menu selection
        System.out.println("Welcome to PurpleHaze ! Please enjoy!");
        // System.out.printf("The average pricing for our drinks is: %.2f \n", + cafeAvg( cafePrice));
        System.out.println("Please enter a menu selection:\n" +
            "0. Momo -- 120\n" +
            "1. Chawmin -- 80\n" +
            "2. Sausages -- 40\n" +
            "3. Pizza -- 100\n" +
            "4. Burger -- 50\n" +
            "5. Buff Sekuwa -- 60\n" +
            "6. Chicken Sekuwa -- 90\n" +
            "7. Alu Paratha -- 45\n" +
            "8. Chicken Chilly -- 70\n" +
            "9. Fry Rice -- 60");

        choice = input.nextInt();

        //Add up the total

        total = Price[choice] + tax;
        System.out.println("Your total is: " + total + tax);
    }

}

I want to add 13% VAT and 10% charge.



Solution 1:[1]

    boolean cont = true;
    while(cont)
    {
        double total = 0;
        int[] choices = new int[5];
        for(int i = 0; i < 5; i++)
        {
            System.out.printf("Enter choice %d%n", i + 1);
            choices[i] = input.nextInt();
        }
        for(int choice : choices)
        {
            System.out.printf("%s | %.2f%n", FoodItem[choice], Price[choice]);
            total += Price[choice];
        }
        total = total * 1.23;
        System.out.println("Your total is: " + total);
        String ask = "";
        while(!ask.equalsIgnoreCase("yes") && !ask.equalsIgnoreCase("no"))
        {
            System.out.println("Continue? (yes/no)");
            ask = input.next();
        }
        cont = ask.equalsIgnoreCase("yes");
    }

Note if a user enters anything other than a number or enters a choice that isn't present in your Price array it'll crash your program. It's best to implement validation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1