|
4 | 4 |
|
5 | 5 |
|
6 | 6 | /** |
7 | | - * Servant offers some functionality to a group of classes without defining that functionality in each of them. |
| 7 | + * Servant offers some functionality to a group of classes without defining that functionality in each of them. |
8 | 8 | * A Servant is a class whose instance provides methods that take care of a desired service, |
9 | 9 | * while objects for which the servant does something, are taken as parameters. |
10 | 10 | * |
11 | 11 | */ |
12 | 12 | public class App { |
13 | | - static Servant jenkins = new Servant("Jenkins"); |
14 | | - static Servant travis = new Servant("Travis"); |
15 | | - |
16 | | - public static void main( String[] args ){ |
17 | | - scenario(jenkins, 1); |
18 | | - scenario(travis, 0); |
19 | | - } |
20 | | - |
21 | | - /* |
22 | | - * Can add a List with enum Actions for variable scenarios |
23 | | - * */ |
24 | | - public static void scenario(Servant servant, int compliment){ |
25 | | - King k = new King(); |
26 | | - Queen q = new Queen(); |
27 | | - |
28 | | - ArrayList<Royalty> guests = new ArrayList<>(); |
29 | | - guests.add(k); |
30 | | - guests.add(q); |
31 | | - |
32 | | - //feed |
33 | | - servant.feed(k); |
34 | | - servant.feed(q); |
35 | | - //serve drinks |
36 | | - servant.giveWine(k); |
37 | | - servant.giveWine(q); |
38 | | - //compliment |
39 | | - servant.GiveCompliments( guests.get(compliment) ); |
40 | | - |
41 | | - //outcome of the night |
42 | | - for(Royalty r : guests) |
43 | | - r.changeMood(); |
44 | | - |
45 | | - //check your luck |
46 | | - if( servant.checkIfYouWillBeHanged(guests) ) |
47 | | - System.out.println(servant.name + " will live another day"); |
48 | | - else |
49 | | - System.out.println("Poor " + servant.name + ". His days are numbered"); |
50 | | - } |
51 | | - |
52 | | - |
| 13 | + static Servant jenkins = new Servant("Jenkins"); |
| 14 | + static Servant travis = new Servant("Travis"); |
| 15 | + |
| 16 | + public static void main(String[] args) { |
| 17 | + scenario(jenkins, 1); |
| 18 | + scenario(travis, 0); |
| 19 | + } |
| 20 | + |
| 21 | + /* |
| 22 | + * Can add a List with enum Actions for variable scenarios |
| 23 | + * */ |
| 24 | + public static void scenario(Servant servant, int compliment) { |
| 25 | + King k = new King(); |
| 26 | + Queen q = new Queen(); |
| 27 | + |
| 28 | + ArrayList<Royalty> guests = new ArrayList<>(); |
| 29 | + guests.add(k); |
| 30 | + guests.add(q); |
| 31 | + |
| 32 | + //feed |
| 33 | + servant.feed(k); |
| 34 | + servant.feed(q); |
| 35 | + //serve drinks |
| 36 | + servant.giveWine(k); |
| 37 | + servant.giveWine(q); |
| 38 | + //compliment |
| 39 | + servant.GiveCompliments(guests.get(compliment)); |
| 40 | + |
| 41 | + //outcome of the night |
| 42 | + for (Royalty r : guests) |
| 43 | + r.changeMood(); |
| 44 | + |
| 45 | + //check your luck |
| 46 | + if (servant.checkIfYouWillBeHanged(guests)) |
| 47 | + System.out.println(servant.name + " will live another day"); |
| 48 | + else |
| 49 | + System.out.println("Poor " + servant.name + ". His days are numbered"); |
| 50 | + } |
53 | 51 | } |
0 commit comments