OOP2

Main.java

1
import java.util.Set;
2
import java.util.ArrayList;
3
import java.util.HashSet;
4
import java.util.Random;
5
6
/**
7
 * The program starts here.
8
 * @author Maarten Vangeneugden - 1438256
9
 */
10
public class Main {
11
	public static void main(String[] args) {
12
		// Starting controllers and linking them together
13
		RoomController roc = new RoomController();
14
		ReservationController rc = new ReservationController(roc);
15
		WalkController wc = new WalkController(rc);
16
17
		addTestRooms(roc);
18
		addTestWalks(wc);
19
		MainWindow mainWindow = new MainWindow(rc, roc, wc);
20
	}
21
22
	/**
23
	 * Generates a series of Rooms to test the program.
24
	 * This method is mostly for debugging purposes.
25
	 * It features a set of constants in the front of the method, which you can
26
	 * edit to your heart's content. =)
27
	 * @param roc The Room Controller to which the Rooms will be added.
28
	 * @pre roc mustn't be null.
29
	 * @throws NullPointerException if roc is a null pointer.
30
	 */
31
	public static void addTestRooms(RoomController roc) {
32
		// Constants; edit to suit your needs
33
		final int ROOM_COUNT = 10; // Amount of Rooms that will be generated
34
		final int MAX_BEDS = 20; // The maximum amount of Beds in 1 Room
35
		final String[] POSSIBLE_FACILITIES = {"Shower", "Curtains", "Airco", "Bath", "Minibar"};
36
		final String[] POSSIBLE_TYPES = {"Male", "Female", "Mixed"};
37
38
		Set<Room> testRooms = new HashSet<>();
39
		for(int i=0; i<ROOM_COUNT; i++) {
40
			Random random = new Random();
41
			int beds = random.nextInt(MAX_BEDS) + 1; // +1, because it's in range [0, MAX_BEDS[
42
			String type = POSSIBLE_TYPES[random.nextInt(POSSIBLE_TYPES.length)];
43
			Set<String> facilities = new HashSet<>();
44
			for(String possibleFacility: POSSIBLE_FACILITIES) {
45
				if(random.nextBoolean()) {
46
					facilities.add(possibleFacility);
47
				}
48
			}
49
			testRooms.add(new Room(beds, type, facilities));
50
			// For debugging purposes, a human readable layout of the Rooms is
51
			// printed:
52
			System.out.println("ROOM");
53
			System.out.println("Beds: "+ beds);
54
			System.out.println("Type: "+ type);
55
			System.out.print("Facilities: ");
56
			for(String facility : facilities) {
57
				System.out.print(facility +", ");
58
			}
59
			System.out.println();
60
			System.out.println("-------------------------------");
61
		}
62
		roc.setRooms(testRooms);
63
	}
64
65
	public static void addTestWalks(WalkController wc) {
66
		ArrayList<String> places = new ArrayList<>();
67
		places.add("Lyon");
68
		places.add("Marseille");
69
		places.add("Paris");
70
		wc.addWalk(new Walk("Tour de France", 5, places));
71
	}
72
}
73