A company has installed a smart elevator system in its office building. The elevator operates based on the following rule.
The elevator can move between 1st to 10th floor
Users can enter their desired floor,but if the floor is outside the range,the system should print “Invalid floor”
The elevator starts from 1st floor and moves to the requested floors one by one,printing each floor it reaches
If the user enters 0, the program should exit with “elevator stopped”
import java.util.*;
class ASC
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int current=1;
while(true)
{
System.out.println(“Enter the floor from 1-10/0 to stop:”);//4
int floor=s.nextInt();//4
if(floor==0)//4==0
{
System.out.println(“Elevator stopped”);
break;
}
else if(floor>10)//4>10
{
System.out.println(“Invalid floor”);
}
else
{
if(floor>current)//4>1
{
for(int i=current+1; i<=floor; i++)//i=4;4<=4
{
System.out.println(“Moving to floor:”+i);//2 3 4
}
}
else if(floor<current)
{
for(int i=current-1; i>=floor; i–)
{
System.out.println(“Moving to floor:”+i);
}
}
else
{
System.out.println(“you are already on floor”+current);
}
current=floor;
}
}
}
}