Question: import java.util.*; public class Demo{ public static void main(String[] args){ int a; int b; int c = 0; int e; Scanner scan = new Scanner(System.in);

import java.util.*; public class Demo{ public static void main(String[] args){ int a; int b; int c = 0; int e; Scanner scan = new Scanner(System.in); while(true){ System.out.println("Please make a selection:"); System.out.println("1.Use Elevator"); System.out.println("2.Quit"); if (c == 0) System.out.println("The elevetor is at basement"); else { System.out.println("The elevator is at floor " + c ); } System.out.print("Please make a selection:"); e = Integer.parseInt(scan.nextLine()); if (e == 2){ break; } if (e == 1){ System.out.print("Select your floor (B,1,2):"); String ch = scan.nextLine(); if(ch.charAt(0) == 'B') b = 0; else if(ch.charAt(0) == '1') b = 1; else b = 2; System.out.print("Select destination floor:"); String next = scan.nextLine(); if(next.charAt(0) == 'B') a = 0; else if(next.charAt(0) == '1') a = 1; else a = 2; if (c == 0) System.out.println("The elevator is at Basement"); else { System.out.println("The elevator is at floor " + c ); } if (c == b){ System.out.println("The Elevator (E) is now open 'O'"); System.out.println("The Elevator (E) is now close 'C'"); if (a < c){ System.out.println("The Elevator (E) is 'U'"); System.out.println("The Elevator (E) is now at " + a ); System.out.println("The Elevator (E) is now open 'O'"); System.out.println("The Elevator (E) is now close 'C'"); c = a; } if (a > c){ System.out.println("The Elevator (E) is 'D'"); System.out.println("The Elevator (E) is now at " + a ); System.out.println("The Elevator (E) is now open 'O'"); System.out.println("The Elevator (E) is now close 'C'"); c = a; } } else { if (b > c){ System.out.println("The Elevator (E) is 'U'"); System.out.println("The Elevator (E) is now at " + b); System.out.println("The Elevator (E) is now open 'O'"); System.out.println("The Elevator (E) is now close 'C'"); c = b; if (a > c){ System.out.println("The Elevator (E) is 'U'"); System.out.println("The Elevator (E) is now at " + a ); System.out.println("The Elevator (E) is open 'O' "); System.out.println("The Elevator (E) is now close 'C'"); c = a; } if (a < c){ System.out.println("The Elevator (E) is 'D'"); System.out.println("The Elevator (E) is now at " + a ); System.out.println("The Elevator (E) is open 'O' "); System.out.println("The Elevator (E) is now close 'C'"); c = a; if (b < c){ System.out.println("The Elevator (E) is 'D'"); System.out.println("The Elevator (E) is now at " + a ); System.out.println("The Elevator (E) is open 'O' "); System.out.println("The Elevator (E) is now close 'C'"); c = b; } } } } } } } }

In Java how do I add to this an output of U as going up one floor and 2U as going up two floors also going down one floor is D and the two floors, 2D? currently it just gives either "U" or "D".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!