Description
Task 1
Create a new project in NetBeans with a class called A2FirstNameLastName.java. Integrate the code provided in the template.
Task 2
The program should do the following:
⦁ Print a welcome message: “Welcome to the NHL play by play event scraper. The system will get events for the specified game for the specified event type.”
⦁ Ask the user for input: “Please enter a valid game number: “. E.g. 20105 which is the 105th regular season game for the current season. Read the input and store it in a variable called int gameNumber.
⦁ If the user enters a string or any special character(basically not a valid number)
Print “Invalid game number. Please try again:”
Else if the user enters a game number less than 20001 or greater than 21230
Print “Invalid game number. Please try again:”
Go back to step 2
Else if the user enters “exit”
Print “Bye”
Exit the program
Else (it is a valid game number)
Go to step 4
⦁ Ask the user for input: “Please enter a valid event type: “ (i.e. the only valid event types is SHOT). Read the input and store it in a variable called String eventType.
⦁ If the user enters an invalid event type
Print “Invalid event type. Please try again:”
Go back to step 4
Else if the user enters “exit”
Print “Bye”
Exit the program
Else (it is a valid event type)
Go to step 6
⦁ Ask the user for which event in the game to extract: “Please enter the nth ” + eventType + ” you would like:”
⦁ If the user enters a non-positive integer
Print “Invalid event number. Please try again:”
Go back to step 6
Else if the user enters “exit”
Print “Bye”
Exit the program
Else (it is a valid event type)
Go to step 8
⦁ Call the method getNthEventByType() to get the nth shot from the HTML report
⦁ Call the method getShotDataFromEventHTML() to extract the shot data in a comma separated String
⦁ We will use a method called writeRecordToFile(int gameNumber, String eventType, String record) to write our records to file. This method will accept three inputs and will write/append to record to a file called
⦁ After control has returned from writeRecordToFile(), report the value of the writeStatus as follows: “The write status is: ” + writeStatus
⦁ Write code for another method called printRecordsFromFile(int gameNumber, String eventType) that reads from
⦁ After control has returned from printRecordsFromFile(int gameNumber, String eventType), report the value of readStatus as follows: “The read status is: “ + readStatus
⦁ Return to step 2.
writeRecordToFile(int gameNumber, String eventType, String record)
The new method called writeRecordToFile accepts three inputs, the game number, the event type and the record, and writes the record out to a file called
We want to keep track of whether the write operation was successful using an int called success. In the try{} block, if there are no errors, change the value of success to 1. If there are IOExceptions and you fall into the catch{} block, print an appropriate error message, and change the value of success to 0. Before ending the method, return this int success variable back to the main() method.
Some parts of the code for this new method is given below. You have to complete it.
public static int writeRecordToFile(int gameNumber, String eventType, String record) throws IOException {
// define the following variables
BufferedWriter outputBuff = null;
int success = -1;
return success;
}
printRecordsFromFile(int gameNumber, String eventType)
public static int printRecordsFromFile (int gameNumber, String eventType) throws IOException {
// write code to read line by line from file and print to screen.
// also create a success variable to indicate the status of the file IO operation
int success = -1;
return success;
}
Deliverables
Please zip your entire project folder containing the src sub-folder and the nbproject subfolder (the others are not necessary). Name the zip file A2FirstNameLastName.zip and submit to Canvas.
Sample Output

