Related questions
Concept explainers
I need help in making the SimulatorSettings and Simulation class for my elevator simulation.
The SimulatorSettings should have setters and getters, it should have variable for the program, and it should also have information take from seetings.txt to run the program
The Simulation should initialize the simulation, create arrayList of Passengers, Elevators and Floors, and also hold the process of the simulation
My code:
Classes requirements:
Elevator {
Holds variable and ArrayList needed for each elevators
Holds setters and getters
}
Standard, Express, Glass, Freight subclasses {
Each keep track of the amount of Elevators
Contains method of generating passengers
}
My code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class Simulation {
SimulatorSettings settings;
public void initSimulation(SimulatorSettings settings) throws FileNotFoundException {
Passenger.passengerCounter = 0;
this.settings = settings;
File file = new File("settings.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.startsWith("floor=")) {
line = line.replace("floor=", "");
settings.setNofloors(Integer.parseInt(line));
}
}
ArrayList<Passenger> passengers = new ArrayList<>();
for (int i = 0; i < 100; i++) {
// Use the percentage from the file
passengers.add(new StandardPassenger());
}
}
}
public class SimulatorSettings {
SimulatorSettings(String fileName){
}
private int nofloors;
public int getNofloors() {
return nofloors;
}
public void setNofloors(int nofloors) {
this.nofloors = nofloors;
}
Building {
private int totalFloors;
private int totalElevators;
private ArrayList<Elevator> elevators;
private ArrayList<Floor> floors;
public Building(int totalFloors, int totalElevators) {
this.totalFloors = totalFloors;
this.totalElevators = totalElevators;
this.elevators = new ArrayList<Elevator>();
this.floors = new ArrayList<Floor>();
// Create elevators
for (int i = 0; i < totalElevators; i++) {
StandardElevator elevator = new StandardElevator(10);
this.elevators.add(elevator);
}
// Create floors
for (int i = 0; i < totalFloors; i++) {
Floor floor = new Floor();
this.floors.add(floor);
}
}
public int getTotalFloors() {
return totalFloors;
}
public int getTotalElevators() {
return totalElevators;
}
public ArrayList<Elevator> getElevators() {
return elevators;
}
public ArrayList<Floor> getFloors() {
return floors;
}
}
Floor {
private ArrayList<Passenger> passengers;
public Floor() {
this.passengers = new ArrayList<Passenger>();
}
public void addPassenger(Passenger passenger) {
this.passengers.add(passenger);
}
public ArrayList<Passenger> getPassengers() {
return passengers;
}
}
}
abstract class Passenger {
private static int passengerCounter = 0;
private String passengerID;
protected int startFloor;
protected int endFloor;
protected static Random rand = new Random();
public Passenger() {
this.passengerID = String.valueOf(passengerCounter);
passengerCounter++;
}
public abstract boolean requestElevator(SimulatorSettings settings);
}
public abstract class Elevator{
private int currentFloor;
private int maxCapacity;
private int passengersCount;
public Elevator(int maxCapacity) {
this.currentFloor = 0; // assuming initial floor is 0
this.maxCapacity = maxCapacity;
this.passengersCount = 0;
}
public abstract void moveUp();
public abstract void moveDown();
public abstract void addPassenger(Passenger passenger);
public abstract void removePassenger(Passenger passenger);
}
class StandardElevator extends Elevator{
public StandardElevator() {
super(10); // max capacity is 10 for StandardElevator
}
@Override
public void moveUp() {
// implementation for moving up for StandardElevator
}
@Override
public void moveDown() {
// implementation for moving down for StandardElevator
}
@Override
public void addPassenger(Passenger passenger) {
// implementation for adding passenger to StandardElevator
}
@Override
public void removePassenger(Passenger passenger) {
// implementation for removing passenger from StandardElevator
}
}
public class FreightElevator extends Elevator{
public FreightElevator() {
super( 4);
}
}
public class GlassElevator extends Elevator{
public GlassElevator() {
super( 8);
}
}
class ExpressElevator extends Elevator{
public ExpressElevator() {
super(8); // max capacity is 8 for ExpressElevator
}
}
Step by stepSolved in 3 steps
- Help, I am making a elevator simulation using polymorphism. I am not sure to do now. Any help would be appreciated. My code is at the bottom, that's all I could think off. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. public abstract class Passenger { public static int passangerCounter = 0; private String passengerID; protected...arrow_forwardHelp, I making a elevator simulator, I need help in writing code in the Elevator class and it's polymorphism class. I am not sure what to do next. Any help is appreciated. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. There are 4 types of elevators in the system:StandardElevator: This is the most common type of elevator and has a request...arrow_forwardYou are given a template to help you follow the required structure. There are 10 files for the base and derived classes with specification and implementation files You are also given a driver MagicalCreaturesMain.cpp that you will complete. So 11 files in all. MagicalCreatureHeader.h // given to you MagicalCreature.cpp // given to you ElfHeader.h // given to you Elf.cpp // you implement methods DragonHeader.h // given to you Dragon.cpp // you implement methods GoblinHeader.h // given to you Goblin.cpp // you implement methods GenieHeader.h // given to you Genie.cpp // you implement methods Specifications: Here are five UML Diagrams: One for the Base class and the others for the derived classes. Use these along with the given template to complete the design of the classes and create the application. The template contains comments and notation as to where you need to fill in the code;...arrow_forward
- Hi, I am making a elevator simulation and I need help in making the passenger classes using polymorphism. Any help is appreciated. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. This is what I have so far // Passenger abstract classpublic abstract class Passenger { protected String type; protected int requestPercentage; public...arrow_forwardThe total cost of a group of items at a grocery store is based on the sum of the individual product prices and the tax (which is 5.75%). Products that are considered "necessities" are not taxed, whereas products that are considered "luxuries" are. The Product class is abstract, and it has a method called getTotalPrice. Your task is to create two subclasses of Product: NecessaryProduct and LuxuryProduct and implement the getTotalPrice method in each of these classes appropriately. Then modify the driver program to instantiate four products (two necessary and two luxury) and store them in the product array, print out each item in the array, and display the total cost of the items. You should not make any changes at all to Product.java, and you should only add to ShoppingTripStartingCode.java. Do not change any code that is already present Example(Cheese and bread are necessities and soda and candy are luxuries)Cheese...arrow_forwardThis is for pygame Ball Class: The Ball class inherits from Drawable and it will draw a circle at its current location. You must implement at the very least the required methods of the base class (draw and get_rect), as well as a constructor. You may need to implement other methods as part of the public interface. This is the Drawable Classarrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY