Exception Project JAVA Create a Java program that searches for a student’s ID or name in a text file, complete the findID() and findName() functions. Then, insert a try/catch statement in main() to catch any exceptions thrown by findID() or findName(), and output the exception message. Each line in the text file contains a name and ID separated by a space. Function findID() has two parameters: a student's name (string) and the text file's contents (infile, input file variable). The function findID() returns the ID associated with the student's name if the name is in the file, otherwise the function throws a runtime error with the message "Student ID not found for studentName", where studentName is the name of the student. Function findName() has two parameters: a student's ID (string) and the text file's contents (infile). The function findName() returns the name associated with the student's ID if the ID is in the file, otherwise the function throws a runtime error with the message "Student name not found for studentID", where studentID is the ID of the student. The main program takes three inputs from a user: the name of a text file (string), the search option for finding the ID or name of a student, and the ID or name of a student (string). If the search option is false, findID() is invoked with the student's name as an argument. If the search option is true, findName() is invoked with the student's ID as an argument. The main program outputs the search result or the caught exception message. Ex: If the input of the program is: roster.txt 0 Reagan and the contents of roster.txt are: Reagan rebradshaw835 Ryley rbarber894 Peyton pstott885 Tyrese tmayo 945 Caius ccharlton329 the output of the program is: rebradshaw835 Ex: If the input of the program is: roster.txt 0 Mcauley the program outputs an exception message: Student ID not found for Mcauley Ex: If the input of the program is: roster.txt 1 rebradshaw835 the output of the program is: Reagan Ex: If the input of the program is: roster.txt 1 mpreston272 the program outputs an exception message: Student name not found for mpreston272 NOTE: Please feel free to make content of your file the way you like. You may use an ArrayList to hold the content of the file. You may change the parameters of your findID or finadName. Hint. Try first to have a file, read the content and print to see it works first.
Exception Project JAVA
Create a Java
Function findID() has two parameters: a student's name (string) and the text file's contents (infile, input file variable). The function findID() returns the ID associated with the student's name if the name is in the file, otherwise the function throws a runtime error with the message "Student ID not found for studentName", where studentName is the name of the student.
Function findName() has two parameters: a student's ID (string) and the text file's contents (infile). The function findName() returns the name associated with the student's ID if the ID is in the file, otherwise the function throws a runtime error with the message "Student name not found for studentID", where studentID is the ID of the student.
The main program takes three inputs from a user: the name of a text file (string), the search option for finding the ID or name of a student, and the ID or name of a student (string). If the search option is false, findID() is invoked with the student's name as an argument. If the search option is true, findName() is invoked with the student's ID as an argument. The main program outputs the search result or the caught exception message.
Ex: If the input of the program is:
roster.txt 0 Reagan
and the contents of roster.txt are:
Reagan rebradshaw835
Ryley rbarber894
Peyton pstott885
Tyrese tmayo 945
Caius ccharlton329
the output of the program is:
rebradshaw835
Ex: If the input of the program is:
roster.txt 0 Mcauley
the program outputs an exception message:
Student ID not found for Mcauley
Ex: If the input of the program is:
roster.txt 1 rebradshaw835
the output of the program is:
Reagan
Ex: If the input of the program is:
roster.txt 1 mpreston272
the program outputs an exception message:
Student name not found for mpreston272
NOTE: Please feel free to make content of your file the way you like.
You may use an ArrayList to hold the content of the file. You may change the parameters of your findID or finadName.
Hint. Try first to have a file, read the content and print to see it works first.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images