Elevator simulation. I need help fixing this class The Simulation Class initializes and holds objects for Passengers, Elevators, and Floors. It reads and parses input files to create the necessary objects and sets the number of simulation iterations. The class also has methods to move the elevators up and down the building, as well as to pick up and drop off passengers. public class Simulation {     private int numFloors;     private ArrayList passengers;     private ArrayList elevators;     private ArrayList floors;     private int numIterations;     public Simulation(String inputFile) throws FileNotFoundException {         passengers = new ArrayList<>();         elevators = new ArrayList<>();         floors = new ArrayList<>();         // Read input file and initialize simulation parameters         Scanner scanner = new Scanner(new File(inputFile));         while (scanner.hasNextLine()) {             String line = scanner.nextLine().trim();             if (line.startsWith("floors=")) {                 numFloors = Integer.parseInt(line.substring(line.indexOf('=') + 1));             } else if (line.startsWith("add_passenger")) {                 String[] parts = line.split("\\s+");                 int startFloor = Integer.parseInt(parts[1]);                 int destFloor = Integer.parseInt(parts[2]);                 PassengerType passengerType = PassengerType.valueOf(parts[3].toUpperCase());                 int percentage = Integer.parseInt(parts[4]);                 passengers.add(new Passenger(startFloor, destFloor, passengerType, percentage));             } else if (line.startsWith("elevator_type")) {

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Elevator simulation. I need help fixing this class The Simulation Class initializes and holds objects for Passengers, Elevators, and Floors. It reads and parses input files to create the necessary objects and sets the number of simulation iterations. The class also has methods to move the elevators up and down the building, as well as to pick up and drop off passengers.

public class Simulation {
    private int numFloors;
    private ArrayList<Passenger> passengers;
    private ArrayList<Elevator> elevators;
    private ArrayList<Floor> floors;
    private int numIterations;

    public Simulation(String inputFile) throws FileNotFoundException {
        passengers = new ArrayList<>();
        elevators = new ArrayList<>();
        floors = new ArrayList<>();

        // Read input file and initialize simulation parameters
        Scanner scanner = new Scanner(new File(inputFile));
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine().trim();
            if (line.startsWith("floors=")) {
                numFloors = Integer.parseInt(line.substring(line.indexOf('=') + 1));
            } else if (line.startsWith("add_passenger")) {
                String[] parts = line.split("\\s+");
                int startFloor = Integer.parseInt(parts[1]);
                int destFloor = Integer.parseInt(parts[2]);
                PassengerType passengerType = PassengerType.valueOf(parts[3].toUpperCase());
                int percentage = Integer.parseInt(parts[4]);
                passengers.add(new Passenger(startFloor, destFloor, passengerType, percentage));
            } else if (line.startsWith("elevator_type")) {
                String[] parts = line.split("\\s+");
                String elevatorType = parts[1];
                int maxCapacity = Integer.parseInt(parts[2]);
                int speed = Integer.parseInt(parts[3]);
                elevators.add(new Elevator(elevatorType, maxCapacity, speed));
            } else if (line.startsWith("request_percentage")) {
                String[] parts = line.split("\\s+");
                String elevatorType = parts[1];
                int percentage = Integer.parseInt(parts[2]);
                for (Elevator elevator : elevators) {
                    if (elevator.getType().equals(elevatorType)) {
                        elevator.setPercentage(percentage);
                        break;
                    }
                }
            } else if (line.startsWith("passenger_request_percentage")) {
                String[] parts = line.split("\\s+");
                PassengerType passengerType = PassengerType.valueOf(parts[1].toUpperCase());
                int percentage = Integer.parseInt(parts[2]);
                for (Passenger passenger : passengers) {
                    if (passenger.getType() == passengerType) {
                        passenger.setPercentage(percentage);
                    }
                }
            } else if (line.startsWith("number_of_elevators")) {
                int numElevators = Integer.parseInt(line.substring(line.indexOf('=') + 1));
                for (int i = 0; i < numElevators; i++) {
                    elevators.add(new Elevator());
                }
            } else if (line.startsWith("run_simulation")) {
                numIterations = Integer.parseInt(line.substring(line.indexOf('=') + 1));
            }
        }

        // Initialize floors
        for (int i = 1; i <= numFloors; i++) {
            floors.add(new Floor(i));
        }

        // Add passengers to floors
        for (Passenger passenger : passengers) {
            floors.get(passenger.getStartFloor() - 1).addPassenger(passenger);
        }
    }

    public void runSimulation() {
        for (int i = 0; i < numIterations; i++) {
            // Move elevators up and down floors
            for (Elevator elevator : elevators) {
                if (!elevator.isBroken()) {
                    Floor currentFloor = elevator.getCurrentFloor();
                    ArrayList<Passenger> passengers = elevator.getPassengers();
                    int numPassengers = passengers.size();

                    // Drop off passengers
                    for (int j = numPassengers - 1; j >= 0; j--) {
                        Passenger passenger = passengers.get(j); 
                    if (passenger.getDestFloor() == currentFloor.getFloorNumber()) {
                        passengers.remove(j)
                    elevator.removePassenger(passenger);
                    }
                    }
                                    // Pick up passengers
                ArrayList<Passenger> passengersToPickUp = currentFloor.getPassengersToPickUp(elevator.getType(), elevator.getPercentage());
                for (Passenger passenger : passengersToPickUp) {
                    if (elevator.addPassenger(passenger)) {
                        currentFloor.removePassenger(passenger);}}}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Math class and its different methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education