Assignment 2 – Read/Write Input/Output (IO)

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (3 votes)

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:
1. 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.”
2. 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 intgameNumber.
3. 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 gamenumber)
Go to step 4
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.
5. 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
6. Ask the user for which event in the game to extract: “Please enter the nth ” + eventType + ” you would like:”
7. 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
8. Call the method getNthEventByType() to get the nth shot from the HTML report
9. Call the method getShotDataFromEventHTML() to extract the shot data in a comma separated String
10. We will use a method called writeRecordToFile(intgameNumber, String eventType, String record) to write our records to file. This method will acceptthree inputs and will write/append to record to a file called _.csv. This method returns and int. In main(), make sure to save the return value in and int called writeStatus.
11. After control has returned from writeRecordToFile(), report the value of the writeStatus as follows: “The write status is: ” + writeStatus
12. Write code for another method called printRecordsFromFile(intgameNumber, String eventType) that reads from _.csv and prints the content to screen. This method has two inputs: 1) game number and 2) event type. This method should also return an int which should be stored in a variable called readStatus in main(). This method should be called from main() after writeRecordToFile() has been called.
13. After control has returned from printRecordsFromFile(intgameNumber, String eventType), report the value of readStatus as follows: “The read status is: “ + readStatus
14. Return to step 2.

writeRecordToFile(intgameNumber, String eventType, String record)
The new method called writeRecordToFileaccepts three inputs, the game number, the event type and the record, and writes the record out to a file called _.csv in append mode (make sure that you are NOT overwriting the file).
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 intwriteRecordToFile(intgameNumber, String eventType, String record) throws IOException {

// define the following variables
BufferedWriteroutputBuff = null;
int success = -1;

return success;
}
printRecordsFromFile(intgameNumber, String eventType)
public static intprintRecordsFromFile (intgameNumber, 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