Biblioteca Java - Blame information for rev 32
Subversion Repositories:
(root)/Courses and labs samples/ISP/Exemple_ISP_Cluj_2015/ElevatorCurs/src/elevatorcurs/model/Elevator.java
Rev | Author | Line No. | Line |
---|---|---|---|
32 | mihai | 1 | |
2 | package elevatorcurs.model; | ||
3 | |||
4 | import java.util.Observable; | ||
5 | |||
6 | /** | ||
7 | * | ||
8 | * @author Mihai Hulea mihai.hulea@aut.utcluj.ro | ||
9 | */ | ||
10 | public class Elevator extends Observable{ | ||
11 | private int position; | ||
12 | private Direction currentDir; | ||
13 | |||
14 | public Elevator() { | ||
15 | currentDir = Direction.HOLD; | ||
16 | } | ||
17 | |||
18 | public void move(){ | ||
19 | switch(currentDir){ | ||
20 | case UP:{ | ||
21 | position = position + 1; | ||
22 | setChanged(); | ||
23 | notifyObservers(this); | ||
24 | break; | ||
25 | } | ||
26 | case DOWN:{ | ||
27 | position = position - 1; | ||
28 | setChanged(); | ||
29 | notifyObservers(this); | ||
30 | break; | ||
31 | } | ||
32 | case HOLD: {} | ||
33 | } | ||
34 | } | ||
35 | |||
36 | public void setCurrentDir(Direction dir){ | ||
37 | this.currentDir = dir; | ||
38 | } | ||
39 | |||
40 | public Direction getCurrentDir(){ | ||
41 | return currentDir; | ||
42 | } | ||
43 | |||
44 | public int getPosition(){ | ||
45 | return position; | ||
46 | } | ||
47 | |||
48 | public String toString(){ | ||
49 | return "Elevator: pos="+position+": dir="+currentDir; | ||
50 | } | ||
51 | } |