-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardGameDriver.java
More file actions
76 lines (66 loc) · 2.63 KB
/
BoardGameDriver.java
File metadata and controls
76 lines (66 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.NoSuchElementException;
/**
* This class is a driver for the BoardGame
* and BoardGameList classes.
* @author Michael Roscoe
*/
public class BoardGameDriver {
public static void main (String[] args) {
System.out.println("Creating board games to test with.");
BoardGame game1 = new BoardGame("Monopoly", 8);
BoardGame game2 = new BoardGame("Yahtzee", 4);
BoardGame game3 = new BoardGame("Connect Four", 2);
BoardGame game4 = new BoardGame("Mousetrap", 6);
BoardGame game5 = new BoardGame("Chess", 2);
BoardGame game6 = new BoardGame("Snakes & Ladders", 3);
System.out.println("\nGames were created:\n");
System.out.println(game1);
System.out.println(game2);
System.out.println(game3);
System.out.println(game4);
System.out.println(game5);
System.out.println(game6);
System.out.println("\nCreating list and adding items.\n");
BoardGameList list = new BoardGameList();
list.add(game3);
list.add(game5);
list.add(game6);
list.add(game1);
list.add(game4);
list.add(game2);
System.out.println("Printing list as an array:\n");
BoardGame[] array = list.getListAsArray();
for (int i = 0; i < array.length; i++) {
System.out.println( "Game " + i + ": " + array[i]);
}
System.out.println("\nRemoving games from the list: ");
System.out.println(game2);
System.out.println(game1);
System.out.println(game5);
list.remove(game1);
list.remove(game2);
list.remove(game5);
System.out.println("\nPrinting new list as an array: \n");
array = list.getListAsArray();
for (int i = 0; i < array.length; i++) {
System.out.println( "Game " + i + ": " + array[i]);
}
System.out.println("\nAdding new items to the list.\n");
list.add(new BoardGame("Risk", 4));
list.add(new BoardGame("Battleship", 2));
System.out.println("Printing new list in reverse:");
array = list.getReversedListAsArray();
for (int i = 0; i < array.length; i++) {
System.out.println( "Game " + i + ": " + array[i]);
}
System.out.println("\nRemoving a game that is not in the list:");
System.out.println(new BoardGame("Game of Life", 6));
try {
list.remove(new BoardGame("Game of Life", 6));
}
catch (NoSuchElementException e) {
System.out.println(e.getMessage());
}
System.out.println("\nNumber of games in the list: " + list.getNumGames());
}
}