Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that mimics the operations of the inside of an elevator. More sp

ID: 3681830 • Letter: W

Question

Write a program that mimics the operations of the inside of an elevator. More specifically, the program simulates what happens when the user chooses to go to a particular floor, and it simulates what happens when the user pulls the elevator's fire alarm. Assume the elevator is in a high-rise building that has floors numbered 1 through 100. Your driver class should call the Elevator class file and implements the requirements above. Refer to the sample output below to see what the prompts and output should look like.Within your driver class, use a loop that continues until the user enters "q" for quit. See the sample session for details .As you implement your solution, you should find that the selectFloor and fireAlarm methods contain some repeated coding logic. To avoid unnecessary redundancies in your code, have those methods call an appropriate helper method. Use a switch statement to handle the different choices for user input. (S-select floor, F-fire alarm, Q-quit). There should also be some coding to recognize which floor the elevator is currently on. Elevator.java Within your Elevator class, include these methods: selectFloor - This method prompts the user for a floor selection and then performs input validation for the floor selection. If the floor selection is inappropriate (less than 1, greater than 100), then the method prints an error message. If the floor selection is OK, the method simulates going to that floor. See the sample session below for the format of the simulation message. fireAlarm - This method prints a "danger" message and then simulates going to the first floor. Note that Im assuming this is a high tech fire alarm that is programmed to force the elevator to go to the first floor! See the sample session below for the format of the "danger" message.

Explanation / Answer

JAVA PROGRAM:

import java.io.*;
import java.util.Scanner;
public class Elevatortest4 {
public static void main(String []args)throws IOException{
int i=1;
String s;
Scanner scan=new Scanner(System.in);
Elevator e=new Elevator();
while(true){
System.out.println("Enter S:selectFloor F:fireAlaram Q:quit");
s=scan.next();
switch(s){
case "S":e.selectFloor();
break;
case "F":e.fireAlaram();
break;
case "Q":System.exit(0);
break;
default:System.out.println("Wrong Option");
}
}
}
}
class Elevator{
public static int currentFloor;
Elevator(){
currentFloor=1;
}
public void selectFloor(){
int floor;
Scanner scan=new Scanner(System.in);
System.out.print("Enter Floor Number:");
floor=scan.nextInt();
System.out.println();
if(floor>=1&&floor<=100){
if(currentFloor<floor)
for(int i=currentFloor;i<=floor;i++)
System.out.println("CurrentFloor is:"+i);
else if(currentFloor>floor)
for(int i=currentFloor;i>=floor;i--)
System.out.println("CurrentFloor is:"+i);
else
System.out.println("Your in the same floor");
System.out.println("Stoped");
currentFloor=floor;
}
else
System.out.println("Wrong floor Number Please enter correct");
}
public void fireAlaram(){
System.out.println("Danger");
for(int i=currentFloor;i>=1;i--)
System.out.println("CurrentFloor is:"+i);
System.out.println("Stoped");
currentFloor=1;
}
}

OUTPUT:

run:
Enter S:selectFloor F:fireAlaram Q:quit
S
Enter Floor Number:4

CurrentFloor is:1
CurrentFloor is:2
CurrentFloor is:3
CurrentFloor is:4
Stoped
Enter S:selectFloor F:fireAlaram Q:quit
S
Enter Floor Number:7

CurrentFloor is:4
CurrentFloor is:5
CurrentFloor is:6
CurrentFloor is:7
Stoped
Enter S:selectFloor F:fireAlaram Q:quit
F
Danger
CurrentFloor is:7
CurrentFloor is:6
CurrentFloor is:5
CurrentFloor is:4
CurrentFloor is:3
CurrentFloor is:2
CurrentFloor is:1
Stoped
Enter S:selectFloor F:fireAlaram Q:quit
S
Enter Floor Number:20

CurrentFloor is:1
CurrentFloor is:2
CurrentFloor is:3
CurrentFloor is:4
CurrentFloor is:5
CurrentFloor is:6
CurrentFloor is:7
CurrentFloor is:8
CurrentFloor is:9
CurrentFloor is:10
CurrentFloor is:11
CurrentFloor is:12
CurrentFloor is:13
CurrentFloor is:14
CurrentFloor is:15
CurrentFloor is:16
CurrentFloor is:17
CurrentFloor is:18
CurrentFloor is:19
CurrentFloor is:20
Stoped
Enter S:selectFloor F:fireAlaram Q:quit
Q
BUILD SUCCESSFUL (total time: 2 minutes 0 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote