Question: Given a main program that searches for the ID or the name of a student from a text file, complete the findID ( ) and
Given a main program that searches for the ID or the name of a student from a text file, complete the findID and the findName methods that return the corresponding information of a student. Then, insert a trycatch statement in main to catch any exceptions thrown by findID or findName and output the exception message. Each line in the text file contains the name and the ID of a student, separated by a space.
Method findID takes two parameters, a student's name and a Scanner object containing the text file's contents. Method findID returns the ID associated with the student's name if the name is in the file, otherwise the method throws an Exception object with the message "Student ID not found for studentName", where studentName is the name of the student.
Method findName takes two parameters, a student's ID and a Scanner object containing the text file's contents. Method findName returns the name associated with the student's ID if the ID is in the file, otherwise the method throws an Exception object 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 a user choice of finding the ID or the name of a student int and the ID or the name of a student String If the user choice is findID is invoked with the student's name as one of the arguments. If the user choice is findName is invoked with the student's ID as one of the arguments. The main program finally outputs the result of the search or a message if an exception is caught.
Ex: If the input of the program is:
roster.txt Reagan
and the contents of roster.txt are:
Reagan rebradshaw
Ryley rbarber
Peyton pstott
Tyrese tmayo
Caius ccharlton
the output of the program is:
rebradshaw
Ex: If the input of the program is:
roster.txt Mcauley
the program outputs an exception message:
Student ID not found for Mcauley
Ex: If the input of the program is:
roster.txt rebradshaw
the output of the program is:
Reagan
Ex: If the input of the program is:
roster.txt mpreston
the program outputs an exception message:
Student name not found for mpreston
use java
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
