Given a main program that searches for the ID or the name of a student from a text file, complete the findlID) and the findName) methods that return the corresponding information of a student. 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 the name and the ID of a student, separated by a space. Method findID0 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 studentlD", 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 0, findID0 is invoked with the student's name as one of the arguments. If the user choice is 1, 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.
Given a main program that searches for the ID or the name of a student from a text file, complete the findlID) and the findName) methods that return the corresponding information of a student. 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 the name and the ID of a student, separated by a space. Method findID0 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 studentlD", 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 0, findID0 is invoked with the student's name as one of the arguments. If the user choice is 1, 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.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Needed code
![1 import java.util.Scanner;
2 import java.io.FileInputStream;
3 import java.io.I0Exception;
4
5 public class LabProgram {
public static String findID(String studentName, Scanner infoScnr) throws Except
8
9.
/* Type your code here.
10
11
12
public static String findName(String studentID, Scanner infoScnr) throws Except
13
14
/* Type your code here. */
15
16 }
17 public static void main(String[] args) throws IOException {
Scanner scnr = new Scanner(System.in);
String studentName;
String studentID;
String studentInfoFileName;
FileInputStream studentInfoStream = null;
Scanner studentInfoScanner = null;
18
19
20
21
22
23
24
// Read the text file name from user
studentInfoFileName = scnr.next();
25
26
27
28
// Open the text file
studentInfoStream = new FileInputStream(studentInfoFileName);
studentInfoScanner = new Scanner(studentInfoStream);
29
30
31
// Read search option from user. 0: findID(), 1: findName()
int userChoice = scnr.nextInt();
32
33
34
35
36
// FIXME: findID() and findName() may throw an Exception.
//
Insert a try/catch statement to catch the exception and output the
37
38
if (userChoice == 0) {
studentName = scnr.next();
studentID = findID(studentName, studentInfoScanner);
System.out.println(studentID);
}
else {
studentID = scnr.next();
studentName = findName(studentID, studentInfoScanner);
System.out.println(studentName);
}
studentInfoStream.close();
39
40
41
42
43
44
45
46
47
48
49
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F722c0934-aff7-4600-989e-1d198e6697ab%2F041526d7-c238-4be0-8270-3569a9d10873%2Fubm3p8d_processed.jpeg&w=3840&q=75)
Transcribed Image Text:1 import java.util.Scanner;
2 import java.io.FileInputStream;
3 import java.io.I0Exception;
4
5 public class LabProgram {
public static String findID(String studentName, Scanner infoScnr) throws Except
8
9.
/* Type your code here.
10
11
12
public static String findName(String studentID, Scanner infoScnr) throws Except
13
14
/* Type your code here. */
15
16 }
17 public static void main(String[] args) throws IOException {
Scanner scnr = new Scanner(System.in);
String studentName;
String studentID;
String studentInfoFileName;
FileInputStream studentInfoStream = null;
Scanner studentInfoScanner = null;
18
19
20
21
22
23
24
// Read the text file name from user
studentInfoFileName = scnr.next();
25
26
27
28
// Open the text file
studentInfoStream = new FileInputStream(studentInfoFileName);
studentInfoScanner = new Scanner(studentInfoStream);
29
30
31
// Read search option from user. 0: findID(), 1: findName()
int userChoice = scnr.nextInt();
32
33
34
35
36
// FIXME: findID() and findName() may throw an Exception.
//
Insert a try/catch statement to catch the exception and output the
37
38
if (userChoice == 0) {
studentName = scnr.next();
studentID = findID(studentName, studentInfoScanner);
System.out.println(studentID);
}
else {
studentID = scnr.next();
studentName = findName(studentID, studentInfoScanner);
System.out.println(studentName);
}
studentInfoStream.close();
39
40
41
42
43
44
45
46
47
48
49
}
![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 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
the name and the ID of a student, separated by a space.
Method findID0 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 0, findID0 is invoked with the student's
name as one of the arguments. If the user choice is 1, 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 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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F722c0934-aff7-4600-989e-1d198e6697ab%2F041526d7-c238-4be0-8270-3569a9d10873%2Fxcppag_processed.jpeg&w=3840&q=75)
Transcribed Image Text: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 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
the name and the ID of a student, separated by a space.
Method findID0 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 0, findID0 is invoked with the student's
name as one of the arguments. If the user choice is 1, 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 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
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY