Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

Did the decisions need to be made, or had they already been made?

Answered: 1 week ago

Question

When there was controversy, was it clear who had the final say?

Answered: 1 week ago