-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
125 lines (111 loc) · 4.64 KB
/
Copy pathMain.java
File metadata and controls
125 lines (111 loc) · 4.64 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Main {
private static List<Project> dataProjects;
private static List<FilmProject> filmProjects;
private static List<MusicProject> musicProjects;
private static List<TheaterProject> theaterProjects;
private static List<TVProject> tvProjects;
public static void main(String[] args) throws IOException, ParseException {
dataProjects = new ArrayList<>();
filmProjects = new ArrayList<>();
musicProjects = new ArrayList<>();
theaterProjects = new ArrayList<>();
tvProjects = new ArrayList<>();
dataReader();
new GUI(dataProjects, filmProjects, musicProjects, theaterProjects, tvProjects);
}
/**
* Method that access the data csv file, parsers line by line and
* create appropriate Project objects based on project_type
* @return
* @throws IOException
* @throws ParseException
*/
public static void dataReader() throws IOException, ParseException {
// Captures user input to determine file path and name
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the input file name (e.g. scotia_visual_productions_projects.csv): ");
String inputFileName = scanner.nextLine();
File dataFile = new File(inputFileName); // Capture existing input file
String newInput;
while (!(dataFile).exists()) {
System.out.print("Provide a valid input file name: ");
newInput = scanner.nextLine();
dataFile = new File(newInput);
}
String line = "";
String splitBy = ","; // set comma as separator
BufferedReader br = new BufferedReader(new FileReader(dataFile));
int iterationCSV = 0; // used to ignore the header row of the csv
while ((line = br.readLine()) != null) //returns a Boolean value
{
if(iterationCSV == 0) { // this line is used to ignore the header row
iterationCSV++;
continue;
}
String[] project = line.split(splitBy); // use comma as separator
String projectId = project[0];
String projectName = project[1];
String projectType = project[2];
Date projectDate = new SimpleDateFormat("dd/MM/yyyy").parse(project[3]);
String projectLocation = project[4];
Double projectCost = Double.parseDouble(project[5]);
Double projectPriceToCustomer = Double.parseDouble(project[6]);
String sizeOfVenue = project[7];
int projectDuration = Integer.parseInt(project[8]);
String projectDurationUnit = project[9];
// Each project will be added to both the All Projects arraylist and the
// specific project type arraylist
if (projectType.equals("Film")) {
// Create new Music Project obj and add it to the ArrayList
String format = project[13];
FilmProject projectObj = new FilmProject(projectId, projectName,
projectDate, projectLocation,projectCost,projectPriceToCustomer,
sizeOfVenue, projectDuration, projectDurationUnit, format);
dataProjects.add(projectObj);
filmProjects.add(projectObj);
}
else if (projectType.equals("Music")) {
// Create new Music Project obj and add it to the ArrayList
String genre = project[12];
MusicProject projectObj = new MusicProject(projectId, projectName,
projectDate, projectLocation,projectCost,projectPriceToCustomer,
sizeOfVenue, projectDuration, projectDurationUnit, genre);
dataProjects.add(projectObj);
musicProjects.add(projectObj);
}
else if (projectType.equals("Theater")) {
// Create new Theater Project obj and add it to the ArrayList
String playwright = project[11];
TheaterProject projectObj = new TheaterProject(projectId, projectName,
projectDate, projectLocation,projectCost,projectPriceToCustomer,
sizeOfVenue, projectDuration, projectDurationUnit, playwright);
dataProjects.add(projectObj);
theaterProjects.add(projectObj);
}
else if (projectType.equals("TV")) {
// Create new TV Project obj and add it to the ArrayList
String network = project[10];
TVProject projectObj = new TVProject(projectId, projectName, projectDate,
projectLocation,projectCost, projectPriceToCustomer,
sizeOfVenue, projectDuration, projectDurationUnit, network);
dataProjects.add(projectObj);
tvProjects.add(projectObj);
}
else {
// Create new Project obj and add it to the ArrayList
Project projectObj = new Project(projectId, projectName, projectType,
projectDate, projectLocation,projectCost,
projectPriceToCustomer, sizeOfVenue, projectDuration,
projectDurationUnit);
dataProjects.add(projectObj);
}
}
}
}