-
Notifications
You must be signed in to change notification settings - Fork 0
/
HotelChooser.java
80 lines (68 loc) · 2.28 KB
/
HotelChooser.java
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
77
78
79
80
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class HotelChooser {
public static void main(String[] args) {
boolean repeat = true;
String name_file;
String input;
while (repeat) {
Scanner scanner = new Scanner(System.in);
System.out.println("\nEnter the input file path above or -1 to stop the program");
System.out.println("Exemple: C:\\Users\\Name\\Downloads\\file_name.txt");
name_file = scanner.nextLine();
if (!name_file.equals("-1")) {
try {
repeat = true;
FileReader file = new FileReader(name_file);
BufferedReader readFile = new BufferedReader(file);
input = readFile.readLine();
InputValidation validation = new InputValidation();
validation.checkInputFile(input);
Hotel hotel1 = new Hotel.HotelBuilder("Lakewood")
.rating(3)
.reward_weekend(80)
.reward_weekday(80)
.regular_weekend(90)
.regular_weekday(110)
.createHotel();
Hotel hotel2 = new Hotel.HotelBuilder("Bridgewood")
.rating(4)
.reward_weekend(50)
.reward_weekday(110)
.regular_weekend(60)
.regular_weekday(160)
.createHotel();
Hotel hotel3 = new Hotel.HotelBuilder("Ridgewood")
.rating(5)
.reward_weekend(40)
.reward_weekday(100)
.regular_weekend(150)
.regular_weekday(220)
.createHotel();
Date date = new Date(input);
CheapestHotel cheapesthotel = new CheapestHotel();
cheapesthotel.calculateCheapestHotel(date, hotel1, hotel2, hotel3);
file.close();
} catch (IOException e) {
System.err.printf("Invalid input file %s.\n \n",
e.getMessage());
repeat = true;
} catch (NullPointerException e) {
System.err.printf("The input file is empty.\n",
e.getMessage());
repeat = true;
} catch (InputMismatchException e) {
System.err.printf("The input file structure is not valid.\n",
e.getMessage());
repeat = true;
}
} else {
repeat = false;
if(scanner!=null) scanner.close();
}
}
}
}