I want the Pegram to go up on floor of there is passengers butit doesn’t change the number of passengers of floor ordirection
pleas help me increase the floor ever time there is passengerand give a random number for direction and passengers
HERE IS main class
package elevator;
import java.util.ArrayList;
import java.util.Random;
public class main {
public staticvoid main(String [] args)
{
ArrayList<elevator> elevator = newArrayList<>(5);
int passengers=0;
int floor=1;
int destiantion=0;
int z=5;
InitializeBuilding(passengers,floor,destiantion);
elevator elv =newelevator(passengers,floor,destiantion);
PrintBuildingStatus(elv);
}
static voidInitializeBuilding(int passengers,int floor , int destiantion)
{
for(int i=0 ; i<5 ;i++)
{
passengers=(int)(Math.random()*5);
floor=1;
destiantion =(int)(Math.random()*6)+1;
floor=i+1;
if(passengers==0)
{
floor=i+2;
}
else if(floor==5 )
{
floor–;
}
else
{
floor=i+1;
}
}
}
static voidPrintBuildingStatus(elevator elv)
{
for(int i=0 ; i<5 ;i++){
System.out.println(elv);
}
}
}
Here is elevator Class
package elevator;
public class elevator {
private int passengers;
private int floor;
private int destiantion;
public elevator(intpassengers, int floor, intdestiantion) {
this.passengers = passengers;
this.floor = floor;
this.destiantion = destiantion;
}
public voidsetPassengers(int p)
{
this.passengers=p;
}
public int getPassengers()
{
return passengers;
}
public int getFloor() {
return floor;
}
public voidsetFloor(int floor) {
this.floor = floor;
}
public int getDestiantion(){
return destiantion;
}
public voidsetDestiantion(int destiantion) {
this.destiantion = destiantion;
}
@Override
public String toString() {
return “elevator [passengers=” + passengers +”, floor=” + floor + “, destiantion=” + destiantion + “]”;
}
}
Expert Answer
Answer to I want the Pegram to go up on floor of there is passengers but it doesn’t change the number of passengers of floor or di…