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

Question #317868

Each customer will type in a code representing the structure of their 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 four optional toppings. The order code positions, from left to right, represent the following elements:




Four optional Items:



1. 'Y' means the customer wants corn (no additional charge), and 'N' means that the customer does not want corn.



2. 'Y' means that the customer wants guacamole ($0.50 extra), and 'N' means that the



customer does not want guacamole.



3.. 'Y' means that the customer wants sour cream (no additional charge), and 'N' means that the customer does not want sour cream.



4.. 'Y' means that the customer wants cheese ($0.50 extra), and 'N' means that the customer


does not want cheese.


1
Expert's answer
2022-03-25T04:37:00-0400
import java.util.Scanner;

public class CashRegister {

    public static String checker(String order){
        Scanner in = new Scanner(System.in);
        boolean trueOrFalse = true;
        while(trueOrFalse==true){
            System.out.println("Enter 'Yes' if you want, or 'No' if you don't want.");
            String check = in.nextLine();
            if("Yes".equals(check)){
                order +="Y";
                trueOrFalse=false;
            }else if("No".equals(check)){
                order+="N";
                trueOrFalse=false;
            }
            else{
                System.out.println("Please input only 'Yes' or 'No'. Thanks.");
            }
        }
        return order;
    }
    public static String orderHandler(String order){
        Scanner in = new Scanner(System.in);
        System.out.println("Do you want corn(no additional charge): ");
        order=checker(order);
        System.out.println("Do you want guacamole ($0.50 extra): ");
        order=checker(order);
        System.out.println("Do you want sour cream (no additional charge): ");
        order=checker(order);
        System.out.println("Do you want cheese ($0.50 extra): ");
        order=checker(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("Y")){
            System.out.println("Corn                   $0  \n");
        }
        else{
            System.out.println("Corn                 Without\n");
        }
        if(order.substring(1,2).equals("Y")){
            sum+=0.5;
            System.out.println("Guacamole              $0.50\n");
        }
        else{
            System.out.println("Guacamole            Without\n");
        }
        if(order.substring(2,3).equals("Y")){
            System.out.println("Sour Cream             $0   \n");
        }
        else{
            System.out.println("Sour Cream           Without\n");
        }
        if(order.substring(3,4).equals("Y")){
            sum+=0.5;
            System.out.println("Cheese                 $0.50\n");
        }
        else{
            System.out.println("Cheese               Without\n");
        }
        System.out.println("----------------------------\n");
        System.out.println("Total:                 $"+sum+" ");
        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