Answer to Question #317866 in Java | JSP | JSF for rose

Question #317866

Each customer will type in a code representing the structure of his or her order, and your program will display (to standard output) a summary of the order components along with the total cost. An order code is exactly nine characters long, representing five required items. The order code positions, from left to right, represent the following elements:

Five required items:

1. 'A' represents a burrito ($3.00), and 'B' represents a burrito bowl ($4.00).

2. 1 represents black beans (no additional charge), and 2 represents pinto beans (no

additional charge).

3. 1 represents white rice (no additional charge), and 2 represents brown rice ($0.50 extra).

4. 1 represents chicken ($2.00 additional), 2 represents carnitas ($2.50 additional), and 3 represents steak ($3.50 additional).

5. 1 represents mild salsa (no additional charge), 2 represents medium salsa (no additional charge), and 3 represents hot salsa (no additional charge).


1
Expert's answer
2022-03-25T05:27:55-0400
import java.util.Scanner;

public class CashRegister {
    public static String checkerBurrito(String order){
        Scanner in = new Scanner(System.in);
        boolean trueOrFalse = true;
        while(trueOrFalse==true){
            String check = in.nextLine();
            if("A".equals(check)){
                order +="A";
                trueOrFalse=false;
            }else if("B".equals(check)){
                order+="B";
                trueOrFalse=false;
            }
            else{
                System.out.println("Please input only 'A' or 'B'. Thanks.");
            }
        }
        return order;
    }

    public static String checkerOneOrTwo(String order){
        Scanner in = new Scanner(System.in);
        boolean trueOrFalse = true;
        while(trueOrFalse==true){
            String check = in.nextLine();
            if("1".equals(check)){
                order +="1";
                trueOrFalse=false;
            }else if("2".equals(check)){
                order+="2";
                trueOrFalse=false;
            }
            else{
                System.out.println("Please input only '1' or '2'. Thanks.");
            }
        }
        return order;
    }
    public static String checkerOneOrTwoOrThree(String order){
        Scanner in = new Scanner(System.in);
        boolean trueOrFalse = true;
        while(trueOrFalse==true){
            String check = in.nextLine();
            if("1".equals(check)){
                order +="1";
                trueOrFalse=false;
            }else if("2".equals(check)){
                order+="2";
                trueOrFalse=false;
            }else if("3".equals(check)) {
                order += "3";
                trueOrFalse = false;
            }
            else{
                System.out.println("Please input only '1' or '2' or '3'. Thanks.");
            }
        }
        return order;
    }


    public static String orderHandler(String order){
        System.out.println("Enter 'A' if you want a burrito bowl($3.00), or 'B' if you want a burrito bowl($4.00):");
        order=checkerBurrito(order);
        System.out.println("Enter '1' if you want black beans(no additional charge), or '2' if you want a pinto beans(no additional charge):");
        order=checkerOneOrTwo(order);
        System.out.println("Enter '1' if you want white rice($0.50), or '2' if you want brown rice($0.50):");
        order=checkerOneOrTwo(order);
        System.out.println("Enter '1' if you want chicken($2.00), or '2' if you want carnitas($2.50), or '3' if you want steak($3.50):");
        order=checkerOneOrTwoOrThree(order);
        System.out.println("Enter '1' if you want mild salsa(no additional charge), or '2' if you want medium salsa(no additional charge), or '3' if you want hot salsa(no additional charge):");
        order=checkerOneOrTwoOrThree(order);
        return order;
    }

    public static void checkCreating(String order){
        double sum=0;
        System.out.println("Your order:\n");
        System.out.println("----------------------------");
            System.out.println("Position               Prise");
        System.out.println("----------------------------\n");
        if(order.substring(0,1).equals("A")){
            sum+=3.0;
            System.out.println("Burrito bowl           $3.00\n");
        }
        else{
            sum+=4.0;
            System.out.println("Burrito bowl           $4.00\n");
        }
        if(order.substring(1,2).equals("1")){
            System.out.println("Black beans            $0.00\n");
        }
        else{
            System.out.println("Pinto beans            $0.00\n");
        }
        if(order.substring(2,3).equals("1")){
            sum+=0.5;
            System.out.println("White rice             $0.50\n");
        }
        else{
            sum+=0.5;
            System.out.println("Brown rice             $0.50\n");
        }
        if(order.substring(3,4).equals("1")){
            sum+=2.0;
            System.out.println("Chicken                $2.00\n");
        }else if(order.substring(3,4).equals("2")){
            sum+=2.5;
            System.out.println("Carnitas               $2.50\n");
        }
        else {
            sum += 3.5;
            System.out.println("Steak                  $3.50\n");
        }
        if(order.substring(4,5).equals("Y")){
            System.out.println("Mild salsa             $0.00\n");
        }else if(order.substring(4,5).equals("2")){
            System.out.println("Medium salsa           $0.00\n");
        }
        else{
            System.out.println("Hot salsa              $0.00\n");
        }
        System.out.println("----------------------------\n");
        System.out.println("Total:                 $"+sum+"0 ");
        System.out.println("\n----------------------------");
    }

    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        String order = "";
        order=orderHandler(order);
        System.out.println();
        checkCreating(order);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS