Uploaded by saif alzoubi

MidExamCS415Section1-form1

advertisement
Jordan University of Science and Technology
CS415 Contemporary Programming Techniques
Midterm Exam – Second semester 2021
Name:
ID:
Section:
Important note: your code must compile correctly and run without errors.
Otherwise your code will get the grade zero.
Question 1: Implement a java class called ParsingStudentRecords that has the
following data members and functions:
ParsingStudentRecords
- StudentRecords: array of strings
- result: string variable
- recordsNumber: int variable
-fileName: string variable
+ Constructor(String filename, int recordsNumber)
+ void Reader()
+ void Executor()
+ void showResult()
+ String toString()
All of the data members are private, and all of the methods are public.
Constructor has two parameters which are (1) the file name in which Students’ records
are stored, and (2) the number of the records in the file. The constructor functionality is to
assign suitable initial values to the fileName and recordsNumber data members. The
constructor also should instantiate the StudentRecords array, where the size of the array
should be equal to recordsNumber.
Reader is a void method that reads the Students’ records file line by line and stores each
record (i.e., each line) at distinct index in the StudentRecords array.
Executor is a void method that goes over all the records at StudentRecords array and
executes each record as explained below:
 Each record has the format: Student-name followed by 3 integer scores separated
by commas as shown in the following example: Ali,80,77,76
 For each record, the Executor function reads the Student name, then reads the
three scores and computes their average, and accumulates the results (i.e., the
Student name and average value) in the result data member.
showResult is a void method that shows the result of records execution (which is stored
in the result data member) to the user using JOptionPane message.
toString is a method that returns the string: “This object stores students records”.
In the main:
1. Read the records file name from user using JOptionPane input dialog. Give the file
this name: StudentRecords.txt
2. Read the records number from user using JOptionPane input dialog
3. Create and instantiate an object of ParsingStudentRecords class. Pass the
filename and records number to the constructor.
4. Call Reader method
5. Call Executor method
6. Call showResult method
7. Print the object that was created in step 2 (using a System.out.println statement).
Download