Я хочу спросить, правильно ли я пишу этот код - PullRequest
0 голосов
/ 06 мая 2019

так что в основном мне нужно создать меню, которое попросит пользователя выбрать еду, а затем продолжать делать это, пока не будет нажата шестерка.Также я должен суммировать деньги, которые пользователь должен дать, и добавить налог в размере 8%.Здесь используется формат «Объявление переменных». Выходное меню «Начать во время цикла» (не используйте номер пункта меню для условия цикла). Запросить номер элемента. Стартовое переключение оператора Каждый случай должен выглядеть следующим образом. Запросить количество Определить цену для заказанных элементов.Упорядоченные элементы. Задание по умолчанию - изменить переменную цикла, чтобы разорвать цикл. Вычислить налог и общий итог. Вывести общее количество элементов, промежуточный итог, налог и общий итог

    import java.util.Scanner;
    public class lab8a{
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //This is the menu that you choose from
      Int sum=0;

         System.out.println("1- Coffee and Donut- $3.50");
        System.out.println("2- Coffee and Bagel- $3.75");
        System.out.println("3- Coffee, Donut and Juice- $4.00");
        System.out.println("4- 1/2 dozen donuts- $5.00");
        System.out.println("5- 1 dozen donuts- $7.50");
    Scanner input1= new Scanner(System.in);
    System.out.print(“Enter 6 to exit or any other # to continue);
   Int cont=input.nextInt();
    System.out.print();          

    while(cont!=6){ 

    Scanner input= new Scanner(System.in);//creates scanner for menu
    System.out.println("choose the number of the order");//order based on 
    integer input
    int menu= input.nextInt();
    System.out.println();//prints out # chosen

    double menu3= menu2;//switches the menu2 to a double to do math with decimals

            switch (menu) {

            case 1:
    Scanner input2= new Scanner(System.in);//second scanner for quantity
    System.out.println("How Many?");
            int item1= input.nextInt();
            System.out.println();//prints out # of orders
       System.out.print("You are ordering " + item1+ " orders of coffee and donut for a total of $" + 3.50*item1);//prints out order and total
            System.out.println("");
        sum+=3.50*item1;
        break;//break for cases
        case 2:
Scanner input3= new Scanner(System.in);//second scanner for quantity
        System.out.println("How Many?");
        int item2= input.nextInt();
        System.out.println();//prints out # of orders
     System.out.print("You are ordering " + item2+ " orders of coffee and bagel for a total of $" + 3.75*item4);
        System.out.println("");
    s+=3.75*item2;
            break;
            case 3: 
    Scanner input4= new Scanner(System.in);//second scanner for quantity
            System.out.println("How Many?");
            int item3= input.nextInt();
        System.out.println();//prints out # of orders
System.out.print("You are ordering " + item3+ " orders of Coffee, Donut, and Juice for a total of $" + 4.00*item3);
        System.out.println("");
s+=4.00*item3
        break;
        case 4:
Scanner input5= new Scanner(System.in);//second scanner for quantity
        System.out.println("How Many?");
        int item4= input.nextInt();
        System.out.println();//prints out # of orders
 System.out.print("You are ordering " + item4+ " orders of 1/2 dozen donuts for a total of $" + 5.00*item4);
        System.out.println("");
s+=5.00*item4;
        break;
        case 5: 
Scanner input6= new Scanner(System.in);//second scanner for quantity
        System.out.println("How Many?");
        int item5= input.nextInt();
        System.out.println();//prints out # of orders
System.out.print("You are ordering " + item5+ " orders of 1 dozen donuts for a total of $" + 7.00*item5);
        System.out.println("");
s+=7.00*item5;
        Break;

 }
System.out.print(“Your subtotal is “ +sum);
System.out.println(“Your total is” + sum*1.08);
 }


so what is supposed to happen is that I ask the user what they want to 
order and continue asking them. Also I have to add up the price of the 
orders and output the overall price when the user exits

1 Ответ

0 голосов
/ 06 мая 2019

попробуйте это:

import java.util.Scanner;
public class lab8a {
public static void main(String[] args) {
    // TODO Auto-generated method stub
    //This is the menu that you choose from
    Scanner input = new Scanner(System.in);
    double sum = 0;
    int choice;

    do{
        System.out.println();
    System.out.println("1- Coffee and Donut- $3.50");
    System.out.println("2- Coffee and Bagel- $3.75");
    System.out.println("3- Coffee, Donut and Juice- $4.00");
    System.out.println("4- 1/2 dozen donuts- $5.00");
    System.out.println("5- 1 dozen donuts- $7.50");
    System.out.println("6- Exit");
    choice = input.nextInt();
    System.out.println("Your Choice is: "+choice);//prints out # chosen
        switch (choice) {

            case 1:
                System.out.println("How Many?");
                int item1 = input.nextInt();
                System.out.println();//prints out # of orders
                System.out.print("You are ordering " + item1 +
                        " orders of coffee and donut for a total of $" + 3.50 * item1);
                //prints out order and total
                System.out.println("");
                sum += 3.50 * item1;
                break;//break for cases
            case 2:
                System.out.println("How Many?");
                int item2 = input.nextInt();
                System.out.println();//prints out # of orders
                System.out.print("You are ordering " + item2 + " orders of coffee and bagel for a total of $" + 3.75 * item2);
                System.out.println("");
                sum+= 3.75 * item2;
                break;
            case 3:
                System.out.println("How Many?");
                int item3 = input.nextInt();
                System.out.println();//prints out # of orders
                System.out.print("You are ordering " + item3 + " orders of Coffee, Donut, and Juice for a total of $" + 4.00 * item3);
                System.out.println("");
                sum+= 4.00 * item3;
                break;
            case 4:
                System.out.println("How Many?");
                int item4 = input.nextInt();
                System.out.println();//prints out # of orders
                System.out.print("You are ordering " + item4 + " orders of 1/2 dozen donuts for a total of $" + 5.00 * item4);
                System.out.println("");
                sum+= 5.00 * item4;
                break;
            case 5:
                System.out.println("How Many?");
                int item5 = input.nextInt();
                System.out.println();//prints out # of orders
                System.out.print("You are ordering " + item5 + " orders of 1 dozen donuts for a total of $" + 7.50 * item5);
                System.out.println("");
                sum+= 7.50 * item5;
                break;


        }
        System.out.println("Your subtotal is " + sum);
        System.out.println("Your total is " + sum * 1.08);
    }while (choice!=6);
 }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...