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.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter11: Exception Handling
Section: Chapter Questions
Problem 2CP
icon
Related questions
Question

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.



Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT