Questions & AnswersJava Programming

Check the calculations because the final price, vat price, and...

Question
Answered step-by-step
Asked by GrandDangerCaribou39 on coursehero.com

Check the calculations because the final price, vat price, and...

Check the calculations because the final price, vat price, and discount price are wrong in the consule:

import java.util.*;
class Main {
    // Calculating VAT value
    public static double calculateVat(double total) {
        double vat = 0.05 * total;
        double final_vat = vat + total;
        double total_price = final_vat - vat;
        return total_price;
    }

    // Calculating discount value
    public static double calculateDiscount(double total) {
        double discount = -0.03 * total; // 3% discount for each item
        double final_discount = total + discount;
        return final_discount;
    }


    // Calculating with discount and VAT
  public static double calculateTotal(double[] totalArray) {
      double total = 0.0;
      for (int i = 0; i < totalArray.length; i++) {
          total = total + totalArray[i];
      }
      double vat = calculateVat(total);
      double discountedTotal = calculateDiscount(total);
      total = vat;
      return vat;
  }


    // Printing welcome at the beginning
    public static void printMessage() {
        String a = new String("HI, welcome to your best Steak house restaurant");
        System.out.println("             " + a.toUpperCase());
    }

    // Printing enjoy your meal at the end
    public static void printdone() {
        String b = new String("Enjoy your meal, and visit us again");
        System.out.println("" + b.toLowerCase());
    }

    // Adding a method to choose the rarity of the steak
    public static String chooseSteakRarity() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Select the rarity of the steak:");
        System.out.println(" 1. Rare");
        System.out.println(" 2. Medium Rare");
        System.out.println(" 3. Medium");
        System.out.println(" 4. Medium Well");
        System.out.println(" 5. Well Done");
        int choice = sc.nextInt();
        switch (choice) {
            case 1:
                return "Rare";
            case 2:
                return "Medium Rare";
            case 3:
                return "Medium";
            case 4:
                return "Medium Well";
            case 5:
                return "Well Done";
            default:
                return "Invalid Choice";
        }
    }

    public static void main(String a[]) {
        printMessage();

        double[] totalArray = new double[4];

        int option, selection, ex;
        do {
            Scanner sc = new Scanner(System.in);
            System.out.println("Enter your choice from the following menu:");
            System.out.println(" 1.Steaks \n 2.sides \n 3.drinks\n 4.Exit\n");
            option = sc.nextInt();
            switch (option) {
                case 1:
                    System.out.println("Select the type of steak that you want from the following menu:");
                    System.out.println(" 1.Ribeye(40 AED)\n 2.Striploin(65 AED)\n 3.Angus(80 AED)\n 4.Wagyu(200 AED)\n");
                    selection = sc.nextInt();
                    if (selection == 1)
                        totalArray[0] = totalArray[0] + 40;
                    else if (selection == 2)
                        totalArray[0] = totalArray[0] + 65;
                    else if (selection == 3)
                        totalArray[0] = totalArray[0] + 80;
                    else if (selection == 4)
                        totalArray[0] = totalArray[0] + 200;

                    // Ask for the rarity of the steak
                    String rarity = chooseSteakRarity();
                    System.out.println("Choose the steak rarity: " + rarity);
                    break;

                case 2:
                    System.out.println("Select the type of sides from the following menu:");
                    System.out.println(" 1.Mash Potatoes(10 AED)\n 2.Boiled veggies corn(15 AED)\n 3.Fresh Salad(15 AED)\n 4.Steamed Rice (20 AED)\n");
                    selection = sc.nextInt();
                    if (selection == 1)
                        totalArray[1] = totalArray[1] + 10;
                    else if (selection == 2)
                        totalArray[1] = totalArray[1] + 15;
                    else if (selection == 3)
                        totalArray[1] = totalArray[1] + 15;
                    else if (selection == 4)
                        totalArray[1] = totalArray[1] + 20;
                    break;

                case 3:
                    System.out.println("Select the drink that you want from the following menu:");
                    System.out.println(" 1.Coca-Cola(5 AED)\n 2.7up (5 AED)\n 3.Fanta (5 AED)\n 4.Mountain Dew (5 AED)\n 5. Water (2 AED) \n");
                    selection = sc.nextInt();
                    if (selection == 1)
                        totalArray[2] = totalArray[2] + 5;
                    else if (selection == 2)
                        totalArray[2] = totalArray[2] + 5;
                    else if (selection == 3)
                        totalArray[2] = totalArray[2] + 5;
                    else if (selection == 4)
                        totalArray[2] = totalArray[2] + 5;
                    else if (selection == 5)
                        totalArray[2] = totalArray[2] + 2;
                    break;

                case 4:
                    break;
                default:
                    System.out.println("Invalid choice?");
            }
            System.out.println(" Want to add something more to your order? 1.Yes or 2.No");
            ex = sc.nextInt();
        } while (ex == 1);

        System.out.println("Your steak price after discount is : " + calculateDiscount(totalArray[0]));
        System.out.println("Your steak final price after VAT is : " + calculateVat(totalArray[0]));



        System.out.println("Your sides price after discount is : " + + calculateDiscount(totalArray[1]));
        System.out.println("Your sides final price after VAT is : " + calculateVat(totalArray[1]));


        System.out.println("Your drinks price after discount is : " + calculateDiscount(totalArray[2]));
        System.out.println("Your drinks final price after VAT is : " + calculateVat(totalArray[2]));


        System.out.println("Your final price  is: " + calculateTotal(totalArray) + " AED");

        Scanner scan = new Scanner(System.in);
        System.out.println("We have a giveaway: a free notebook");
        int qty = 0;
      String[] giveawayArray = { "Blue", "Black", "White" };
      int[] qtyArray = { 2, 2, 3 };     //ask the user for color of nootbook
      System.out.println("Enter the color of notebook you want : (Blue/Black/White) ");
      String giveaway = scan.next();

        for (int i = 0; i < 3; i++) {
            if (giveawayArray[i].equals(giveaway)) {
                qty = qtyArray[i] - 1;
                System.out.println("The color of the notebook you chose is: " + giveaway);
                break;
            }
        }

        if (qty == 0)
            System.out.println("The notebook is not available");

        printdone();
}
}

Answer & Explanation

Solved by verified expert
Answered by vinayjadhav612 on coursehero.com

sectetur

 

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec alique
sectetur
CliffsNotes Logo

Unlock access to this and over
10,000 step-by-step explanations

Unlock Explanation

Have an account? Log In

<pre><code class="language-plaintext">sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing</code></pre><p> </p><p> </p><p> </p><p>sectetur adipiscing</p>

Step-by-step explanation

 

 

sectetur adipiscing e

  • sectetur adipiscing elit. Nam lacini
    sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus ef
    sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. P
    sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus ef
  • sectetur adipiscing elit. Nam la
    sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoree
  • sectetur adipiscin
    sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie conseq
  • sectetur adipiscing
    sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, d
  • sectetur adipiscing el
    sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur l

    sectetur adip

 

Get unstuck with a CliffsNotes subscription

Example CliffsNotes Question and Answer
Unlock every step-by-step explanation, download literature note PDFs, plus more.Get Access

Related Q&A