1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
amm1812
4 years ago
15

1. Define class Elevator. For simplicity, we do not consider property like capacity (or weight limit), door (open or close), or

status (running, maintenance, alarm). (a) Data members of an elevator can be as follows, they are all ints. currentFloor, baseFloor, and topFloor; (b) Define constructors for Elevator class.A default constructor setting baseFloor to be 1, and topFloor to be 6, and currentFloor to be1. Define an non-default constructor public Elevator(int currentFloor, int baseFloor, int topFloor), where topFloor should be at least 2, baseFloor should be smaller than topFloor, and currentFloor is somewhere between baseFloor and topFloor. (c) Define method up with a given parameter numFloors (an int). If numFloors is positive, then move that many floors up from the currentFloor, update value for currentFloor. Note that after you run this method, currentFloor cannot be bigger than topFloor.(d) Define method down with a given parameter numFloors (an int). if numFloors is positive, then move that many floors down from the currentFloor, update value for currentFloor. Note that after you run this method, currentFloor cannot be smaller than the baseFloor.(e) Define a getter for each data member. (f) NO need to define other method.2. Define Passenger class. It takes data members: currentFloor and targetFloor. Both are ints.(a) Define constructor of Passengers. This constructor takes two int parameters, use them to initialize the corresponding data member.(b) Define a getter for each data member.(c) NO need to define other methods.3. Define class PassengersTakeElevator. (a) Define data member as an elevator and a list of passengers (read API of ArrayList). The main difference between an array and a list is that a list can grow (add an element to the list) or shrink (remove an element from the list) dynamically; however, to access an individual element, we need to start from the head of the list.(b) Define a default constructor, use an elevator created from a default constructor, and build a list of three passenger. For each passenger, currentFloor and targetFloor are random ints between the baseFloor and topFloor of the elevator. Note that for each passenger, currentFloor cannot be the same as targetFloor (otherwise, there is no need to move the passenger using elevator).(c) Define a non-default constructor that takes an elevator and a list of passengers.(c) Define method schedule. Let the elevator serve passengers in the first-in and first-out order. For simplicity, you can assume that2 there is only one elevator, and the elevator can only carry one passenger a time. For each passenger, we first need to move the elevator to the current floor of that passenger if the elevator is not in that floor yet. Then bring the passenger to his/her target floor.Print out a message every time the elevator movesFor example, Passenger 0 is at Fl 5, will go to Fl 2 elevator is at Fl 1 elevator moves up from Fl 1 to Fl 5 elevator carries passenger down from Fl 5 to Fl 24. Define a client class to test PassengersTakeElevator.A sample output may look like:A. Passenger 0 is at Fl 5, will go to Fl 2 elevator is at Fl 1 elevator moves up from Fl 1 to Fl 5 elevator carries passenger down from Fl 5 to Fl 2B. Passenger 1 is at Fl 3, will go to Fl 2 elevator is at Fl 2 elevator moves up from Fl 2 to Fl 3 elevator carries passenger down from Fl 3 to Fl 2C. Passenger 2 is at Fl 4, will go to Fl 3 elevator is at Fl 2 elevator moves up from Fl 2 to Fl 4 elevator carries passenger down from Fl 4 to Fl 3
Computers and Technology
1 answer:
mihalych1998 [28]4 years ago
7 0

Answer:

The source code is given below using Java

Explanation:

/*

* File: Passenger.java

*/

public class Passenger {

int currentFloor,targetFloor;//data members

//argumented constructor

public Passenger(int currentFloor, int targetFloor) {

this.currentFloor = currentFloor;

this.targetFloor = targetFloor;

}

//getter method

public int getCurrentFloor() {

return currentFloor;

}

//getter method

public int getTargetFloor() {

return targetFloor;

}

 

}

/***********************/

/*

File: Elevator.java

*/

public class Elevator {

int currentFloor, baseFloor, topFloor;//data members

public Elevator()//default constructor

{

baseFloor=1;

topFloor=6;

currentFloor=1;

}

//argumented constructor

public Elevator(int currentFloor, int baseFloor, int topFloor)

{ if(topFloor>=2 && baseFloor < topFloor && currentFloor>baseFloor && currentFloor < topFloor)

{

this.baseFloor=baseFloor;

this.topFloor=topFloor;

this.currentFloor=currentFloor;

}

else

{

baseFloor=1;

topFloor=6;

currentFloor=1;

}

}

// up method

public void up(int numFloors )

{

if(numFloors>0 && currentFloor+numFloors <=topFloor)

currentFloor+=numFloors;    

}

// down method

public void down(int numFloors )

{

if(numFloors>0 && currentFloor-numFloors >=baseFloor)

currentFloor-=numFloors;

}

//getter method

public int getCurrentFloor() {

return currentFloor;

}

//getter method

public int getBaseFloor() {

return baseFloor;

}

//getter method

public int getTopFloor() {

return topFloor;

}

 

}

/****************************/

/*

* File: PassengersTakeElevator.java

*/

import java.util.ArrayList;

public class PassengersTakeElevator {

//data members

Elevator elevator;

ArrayList <Passenger> passengers;

//default constructor

public PassengersTakeElevator() {

passengers=new ArrayList<>();

elevator=new Elevator();

Passenger p0=new Passenger(5, 2);

passengers.add(p0);

Passenger p1=new Passenger(3, 2);

passengers.add(p1);

Passenger p2=new Passenger(4, 3);

passengers.add(p2);

}

//argumented constructor

public PassengersTakeElevator(Elevator elevator, ArrayList<Passenger> passengers) {

this.elevator = elevator;

this.passengers = passengers;

}

//schedule method

public void schedule(){

for(int i=0;i<3;i++)

{

Passenger p=passengers.get(0);//gets passenger at head

 

System.out.println("Passenger "+i+" is at Fl "+p.getCurrentFloor()+", will go to Fl "+p.getTargetFloor());

System.out.println("Elevator is at Fl "+elevator.getCurrentFloor());

int numFloors=p.getCurrentFloor()-elevator.getCurrentFloor();

if(numFloors>0)

{

System.out.println("Elevator moves up from Fl "+elevator.getCurrentFloor()+" to Fl "+p.getCurrentFloor());

elevator.up(numFloors);

System.out.println("Elevator carries passenger down from Fl "+p.getCurrentFloor()+" to Fl "+p.getTargetFloor());

numFloors=p.getCurrentFloor()-p.getTargetFloor();

elevator.down(numFloors);

}

else if(numFloors<0)

{

System.out.println("Elevator moves down from Fl "+elevator.getCurrentFloor()+" to Fl "+p.getCurrentFloor());

elevator.down(-numFloors);

System.out.println("Elevator carries passenger up from Fl "+p.getCurrentFloor()+" to Fl "+p.getTargetFloor());

numFloors=p.getTargetFloor()-p.getCurrentFloor();

elevator.up(numFloors);

 

}

else

{ numFloors=p.getTargetFloor()-p.getCurrentFloor();

if(numFloors>0)

{

System.out.println("Elevator carries passenger up from Fl "+p.getCurrentFloor()+" to Fl "+p.getTargetFloor());

elevator.up(numFloors);

}

else

{

System.out.println("Elevator carries passenger down from Fl "+p.getCurrentFloor()+" to Fl "+p.getTargetFloor());

elevator.down(-numFloors);

}

}

passengers.remove(0);//removes passenger at head

}

}

}

/*****************************/

/*

* File: TestPassengersTakeElevator.java

*/

import java.util.ArrayList;

public class TestPassengersTakeElevator {

public static void main(String[] args) {

//object of PassengersTakeElevator

System.out.println("Schedule 1");

PassengersTakeElevator obj1=new PassengersTakeElevator();

obj1.schedule();//calling schedule method of PassengersTakeElevator

ArrayList <Passenger> passengers=new ArrayList<>();

Elevator elevator=new Elevator();

Passenger p0=new Passenger(1, 5);

passengers.add(p0);

Passenger p1=new Passenger(2, 4);

passengers.add(p1);

Passenger p2=new Passenger(4, 1);

passengers.add(p2);

System.out.println();

System.out.println("Schedule 2");

PassengersTakeElevator obj2=new PassengersTakeElevator(elevator,passengers);

obj2.schedule();//calling schedule method of PassengersTakeElevator

 

 

}

 

}

You might be interested in
The _______ "represents a set of features that enables the user to inform himself whether a security feature is in operation or
quester [9]

Answer:

Visibility and configuration of security.

Explanation:

The visibility and configuration of security represents a set of features that enables the user to inform himself whether a security feature is in operation or not and whether the use and provision of services should depend on the security feature.

4 0
4 years ago
I NEED HEP QUICK
avanturin [10]

Answer:

O = (C2+C3+C4+C5)-81

Explanation:

5 0
2 years ago
Mike recently started using Google Display Ads to create a more automated approach to managing his campaigns. What's one automat
Marysya12 [62]

Answer:

Automated targeting

Explanation:

Display Automated Targeting is an automated targeting option within the Audience settings of the display campaigns that gives Google full right to show your ads to an audience that is “similar” to the one you specified.

8 0
3 years ago
An example of a(n) ____ reconnaissance attack is a user who sends SQL injections to a system in hopes of generating some type of
Elden [556K]
The answer to this question is A
7 0
3 years ago
Read 2 more answers
John would like to move from the city into the suburbs and has been saving up a large down payment for a home. which is the most
Murrr4er [49]
When we say suburban area, this is the area that is only a part of the city or a region that is distant from the city but not to the point that it becomes rural. So for John, the best way for him to save up in order to acquire a place to stay in the suburbs is to move first to the suburbs and rent a home for a year. This would give John enough time to decide whether he would like the suburban living and to look for a perfect location for his house.
8 0
3 years ago
Other questions:
  • The following is true about SPAM ________.
    9·1 answer
  • Radiation requires a heated liquid to transfer energy. Please select the best answer from the choices provided T F
    10·2 answers
  • Which statement about images is correct? A) A virtual image cannot be formed on a screen. B) A virtual image cannot be viewed by
    12·1 answer
  • 3. A vulnerability is: a. A hacker searching for open ports b. A known attack method c. An incorrectly implemented policy d. All
    7·1 answer
  • What kind of negative social impact has wireless communications had on today's society?
    6·2 answers
  • 1)Write the command that moves the file data1 into the directory testdata:
    9·1 answer
  • Vannevar Bush imagined a desktop computing machine that would allow people to access data stored in various information centers
    13·1 answer
  • The Review tab in Microsoft Publisher provides two groupings called _____. Proofing and Language Spell Check and Research Proofi
    6·1 answer
  • If I am working in a document and wish to follow a hyperlink, what should I do?
    7·1 answer
  • Which of the following is an antivirus software?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!