Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In JAVA write a program to simulate a small application system of student data. You will need to write three java files, Student.java, StudentApplication.java, and

In JAVA write a program to simulate a small application system of student data. You will need to write three java files, Student.java, StudentApplication.java, and StudentNotFoundException.java. The Student class represents a single student. It includes constructors and a set of methods. The StudentApplication class includes the main method that reads data from an input file, allows user to search a student by id or name, allows user to change major, and save back to the file if the data are modified. The StudentNotFoundException class is an exception class. In the main method, the program first reads the student roster from an input file. The input file should be named assg4_input.txt. While the information for a student is read, it should be stored into an array. The element type of the array should be Student (which is a class you will write). You may assume that the input file has no more than 100 students (so the array size can be set to 100). The input file should be placed in your CSCI 2540_S23 Java project folder in Eclipse (outside of src folder). In the input file, there is one line per student with the following format: id, name, gender, dateOfBirth, major or: id, name, gender, dateOfBirth where id represents student id, name represents student name, while gender is char type (for example, F for female, and M for male), dateOfBirth is a string in the format of mm-dd-yyyy, and major represents the students major of study. If no major is provided, set the major to undeclared. Columns are separated by ,. A sample input file is posted on Canvas. After all the student data are stored in the array, your program should print the information of allthe students and the total number of students. The program then displays the following menu: 1. Search student by id 2. Search student by name 3. Change student major 4. Exit For the first two choices, the program should ask user to enter an id (if 1 is selected) or a name (if 2 is selected), and it should print the complete information of the student if found. If not found, a message will be printed using exception handling. The output should include the id, name, gender, dateOfBirth, and major, printed on a single line. If a user chooses 3, the program should ask user to enter a student id and new major. If the id is found, the major is changed to the new one. Otherwise, it will display a message using exception handling.

Your program should continue to display the menu to allow user to make more selections until the user chooses to exit. Your program needs to include exception handling code. The following error is possible and should be handled by your program: Student not found. This exception is thrown if a student id or a name is not found.

You need to create StudentNotFoundException class. When the exception happens, your program should handle it by writing an error message. The StudentNotFoundException class should be defined as a checked exception. It should include two constructors. One is the default constructor, and the other is one-parameter constructor and the parameter type is String. In summary, your source code should be developed in three files: Student.java, StudentApplication.java, and StudentNotFoundException.java. Student.java will contain the class definition for a student according to the requirements. StudentSearch.java will be the application program that includes the main method to read from input file, store the data into an array, display the menu, perform search or other options, and handle exception. StudnetNotFoundException.java will define the checked exception. For the student class, define instance variables of the appropriate type for the information about each student. Instance variables should be private. The following methods are required for the Student class. One constructor with the given id, name, gender, date of birth, and major. Another constructor with the given id, name, gender, and date of birth. Set major to undeclared. The get method for each instance variable. The set method for major. The toString method that takes no parameter and returns all the information of the student as a combined string. A static method StudentSearchByName that takes three input parameters: (1) an array of Student objects that represent the entire roster; (2) an integer specifying how many students are stored in the array; and (3) student name. The method should search the array of students looking for the student with the given name. The method should return the index within the array. If the student name is not found, the method should throw a StudentNotFoundException, but it is not handled in this method. Instead, it will be handled in the main method where it is called. A static method StudentSearchById that takes three input parameters: (1) an array of Student objects that represent the entire roster; (2) an integer specifying how many students are stored in the array; and (3) student id. The method should search the array of students looking for the student with the given id. The method should return the index within the array. If the student id is not found, the method should throw a StudentNotFoundException, but it is not handled in this method. Instead, it will be handled in the main method where it is called. Sample input file: B10001,John Smith,M,12-30-1981,Mechanical Engineering B12345,Emily Johnson,F,10-15-1975,Computer Science B34218,David Baker,M, 1-30-1985,Business Administration G24510,Jane Doe,F,10-20-1990 G33567,Riley Washington,M,2-2-1999,Computer Science

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions