Draw a UML diagram of the following classes? The classes of this program represent an elevator. Press of button 1, 2, or 3 brings you to that Floor. public class Elevator { Floor floor; Context context; State closedState; State openState; State state; public Elevator() { floor = new Floor(1); context = new Context(); closedState = new ClosedState(); openState = new OpenState(); state = openState; state.doAction(context); } public static void main(String[] args) { Elevator elevator = new Elevator(); elevator.press2(); elevator.press1(); elevator.press3(); elevator.press3(); elevator.press1(); } public void move(Floor floor, int requestedFloor) { String door = context.getState().toString(); String closed = "Doors are closed"; System.out.println("\n"+ requestedFloor + " pressed"); if(!door.equals(closed)) { state = closedState; closeDoors(); } if (requestedFloor == floor.getFloor()) { System.out.print("Nothing happens"); }else if (requestedFloor < floor.getFloor()) { floor.setFloor(requestedFloor); System.out.printf("Going down...\n*ding* The elevator arrives at Floor %d", floor.getFloor()); state = openState; openDoors(); }else { floor.setFloor(requestedFloor); System.out.printf("Going up...\n*ding* The elevator arrives at Floor %d", floor.getFloor()); state = openState; openDoors(); } } private void press1() { move(floor,1); } private void press2() { move(floor,2); } private void press3() { move(floor,3); } private void openDoors() { state.doAction(context); System.out.print(context.getState().toString()); } private void closeDoors() { state.doAction(context); System.out.println(context.getState().toString()); } }   public class ClosedState implements State { @Override public void doAction(Context context) { context.setState(this); } public String toString(){ return "Doors are closed"; } }   public class Context { private State state; public Context() { state = null; } public void setState(State state){ this.state = state; } public State getState(){ return state; } }   public class Floor { private int floor; public Floor(int num){ this.floor = num; } public int getFloor() { return floor; } public void setFloor(int num) { this.floor = num; } }   public class OpenState implements State { @Override public void doAction(Context context) { context.setState(this); } public String toString(){ return "Doors are open"; } }   public interface State { void doAction(Context context); }

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
100%

Draw a UML diagram of the following classes?

The classes of this program represent an elevator. Press of button 1, 2, or 3 brings you to that Floor.

public class Elevator {
Floor floor;
Context context;
State closedState;
State openState;

State state;

public Elevator() {
floor = new Floor(1);
context = new Context();
closedState = new ClosedState();
openState = new OpenState();

state = openState;
state.doAction(context);
}

public static void main(String[] args) {
Elevator elevator = new Elevator();
elevator.press2();
elevator.press1();
elevator.press3();
elevator.press3();
elevator.press1();
}

public void move(Floor floor, int requestedFloor) {
String door = context.getState().toString();
String closed = "Doors are closed";
System.out.println("\n"+ requestedFloor + " pressed");
if(!door.equals(closed)) {
state = closedState;
closeDoors();
}
if (requestedFloor == floor.getFloor()) {
System.out.print("Nothing happens");
}else if (requestedFloor < floor.getFloor()) {
floor.setFloor(requestedFloor);
System.out.printf("Going down...\n*ding* The elevator arrives at Floor %d", floor.getFloor());
state = openState;
openDoors();
}else {
floor.setFloor(requestedFloor);
System.out.printf("Going up...\n*ding* The elevator arrives at Floor %d", floor.getFloor());
state = openState;
openDoors();
}
}

private void press1() { move(floor,1); }

private void press2() { move(floor,2); }

private void press3() { move(floor,3); }

private void openDoors() {
state.doAction(context);
System.out.print(context.getState().toString());
}

private void closeDoors() {
state.doAction(context);
System.out.println(context.getState().toString());
}
}

 

public class ClosedState implements State {

@Override
public void doAction(Context context) { context.setState(this); }

public String toString(){
return "Doors are closed";
}
}

 

public class Context {
private State state;

public Context() { state = null; }

public void setState(State state){
this.state = state;
}

public State getState(){
return state;
}
}

 

public class Floor {
private int floor;

public Floor(int num){ this.floor = num; }

public int getFloor() { return floor; }

public void setFloor(int num) { this.floor = num; }
}

 

public class OpenState implements State {
@Override
public void doAction(Context context) { context.setState(this); }

public String toString(){ return "Doors are open"; }
}

 

public interface State {
void doAction(Context context);
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
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