QuestionQuestion

Fundamentals of Computer Science I

20 Points Programming Assignment #4

Learning Objectives:

• Writing a small Java class, with associated methods
• Writing and running a small Java driver program involving file processing on BlueJ IDE

Problem: We need to a write a small program that will read a file in which each line contains information about one student – bannerID, creditsCompleted, cumulativeGPA, and name.

We need to process the information and print a report of all students in decreasing order of cumulativeGPA.

For example, consider the following line:

800987654       120             2.00 John Smith

It indicates that John Smith has a BannerID of 800987654, has completed 120 credits and has a cumulative GPA of 2.00.
Note that the name may involve one or more parts and hence the fourth piece of information is read as the name till end of line (that is, use readLine method).

For the purpose of keeping information about students, we will define a class named Student.
As each line of information is read, we will create a Student object and place it in an array named activeStudents.
Eventually, we sort this array of Student objects on the basis of cumulativeGPA and print a report.
Assume that the file has all the fields in proper place in each line and there are no problem records.

Specification of Student class

a. Each Student object has four instance variables:
• bannerID, a String (not an int),
• name, a String,
• creditsCompleted, an int, and
• cumulativeGPA, a double.

b. The constructor has four parameters, corresponding to the four   instance   variables, with the same name.   
The constructor initializes the instance variables.

c. There are four getter methods, again one corresponding to each of the four instance variables.

d. The toString method returns a String.
It is the concatenation of the values of the four instance variables in this specific order: cumulativeGPA, creditsCompleted, bannerID, and name.

A tab character is inserted between the pieces during concatenation. In addition, the cumulativeGPA is formatted with one digit before and two digits after the decimal point e.g., 3.45).
The creditsCompleted is formatted as a three digit number with leading zeroes, if any. (See the Major class in Lab 09 for similar code.)

Specification of the Database class

a. It contains just one main method. All the code for file processing, sorting, etc., are in this method.

b. For the purpose of the program, it is appropriate to assume that there are at most 256 student records in the file. (Optional: Find a way to handle arbitrary number of student records.)

c. The main method should display the purpose of the program and prompts the user for the name of input data file and read it.

d. The main method should attempt to open the file. If the file does not exist or there is problem in opening the file, report an error and exit. (Use try and catch similar to Lab 09.)

e. Else, process the file.

After all the student records are read, sort the array of Student objects in decreasing order of cumulativeGPA, and print the report.

Each line also carries a statement that the student is Ready to graduate if cumulativeGPA >= 2.00 and creditsCompleted >= 120. (Do not modify the toString method.

This remark regarding readiness to graduate is added while printing the report.)

Sample Output to show prompts and messages

First run

This program processes a text file containing student information, and generates a report in descending order of GPA.

Author:

Enter file name (show complete path): P:\Data\Prog4Data00.txt

The file P:\Data\Prog4Data00.txt was not found.

Second run

This program processes a text file containing student information, and generates a report in descending order of GPA.

Author: Version:
Enter file name (show complete path): P:\Data\Prog4Data01.txt

Number of students processed: 3
Below is the list of students in decreasing order of cumulative GPA
-------------------------------------------------------------------
3.90 090 800234567 Jedd Bartlet
3.50 120 800345678 Kad Lakshmanan Ready to graduate
2.20 034 800123456 Bob Russel

Program has terminated.

Program

Write a complete, well-structured, modular Java program to accomplish the above task.
First complete the code for the class Student.
Then work on the class Database.

If you are not able to determine the logic for sorting, skip that at this point in time.
Be sure that your output matches the sample output in terms of prompts and messages.

Your program should be written taking into account good programming practices discussed in class.
The program should be typed following the pretty-printing and indentation styles shown in the book.

Adequate documentation to explain the purpose and the logic of the program, the role played by the variables, programmer identification, etc., should be included.

Compile, execute and test the program thoroughly on the four test case files provided.
Also test the program for a non-existing file.

After you are sure the program works fine and the output is what you need, Clear the terminal window, set the terminal window option to unlimited buffering, and run all four test cases systematically.
Also run at least one test case for non-existing file name.

• Print the source code for Database in landscape orientation.   
Print the source code for Student in landscape orientation.

• Save and print the terminal window, in landscape orientation, showing the program output for all four test cases in the Blackboard site. Also run at least one test case for non-existing file name. (Total of five test cases.)

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

    By purchasing this solution you'll be able to access the following files:
    Solution.pdf, Solution1.pdf, Solution2.pdf and Solution.zip.

    $35.00
    for this solution

    or FREE if you
    register a new account!

    PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

    Find A Tutor

    View available Java Programming Tutors

    Get College Homework Help.

    Are you sure you don't want to upload any files?

    Fast tutor response requires as much info as possible.

    Decision:
    Upload a file
    Continue without uploading

    SUBMIT YOUR HOMEWORK
    We couldn't find that subject.
    Please select the best match from the list below.

    We'll send you an email right away. If it's not in your inbox, check your spam folder.

    • 1
    • 2
    • 3
    Live Chats