Question: Computer Science computer sciencee 9 Methods Please follow the instructions exactly. Do not create additional methods or instance variables public void takeAttendance ( ) o
Computer Science computer sciencee
Methods
Please follow the instructions exactly. Do not create additional methods or instance variables
public void takeAttendance o The first part will be processing the input file, where we will extract an array of Strings representing the names we want to use to take attendance. If this operation is not successful, no further steps should be executed.
The input file has a specific format, storing all its information in a single line.
You should open the input file with a Scanner. If the Scanner throws a FileNotFoundException, it should let it propagate.
Because it's a checked exception, you will have to change the method header.
If the file is completely empty, you should throw a BadFileException with the following message: "The input file was empty" and end here.
You should use nextLine in the scanner to get all the information in one go
When that doesn't work, it will throw a
NoSuchElementException. You can catch that exception and throw a BadFileException inside the catch.
Otherwise, continue: A valid file has to start with and has to end with with both have characters and no spaces If any of these isn't present, or if the file has less than characters main reason: to avoid considering or as valid you should throw a BadFileException with the message: "The file doesn't have correct beginning or end"
If none of the previous checks trigger, the file is considered valid. Remove the beginning and end the characters and split the remaining characters with the separator hyphenes, no spaces, use the split method The resulting array of Strings will be the array having the names. With the names obtained, you should close the input file.
If a BadFileException or FileNotFoundException occurs, you shouldn't catch it let it propagate. You must make sure that the input file is closed regardless of whether an exception is thrown or not.
Hint: There's a keyword that can be used in combination with a trycatch to achieve this behavior.
Make sure to store the array of String outside of the previous block of code so it can be accessed later. If it's a local variable inside a try block, it won't be able to be accessed after it ends. Declare the array outside the try and set it to null initially.
For the second part, we will use a helper method to take the attendance. o Create a Scanner from
System.in and a PrintWriter for the output file. You won't use them on this function, instead, you will pass them to a helper function that will be described after this one.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
