Microsoft Word - JL_BCS345_201_homework3.docx
BCS 345: Java Programming
CRN 21177, 25160 JL Spring 2020
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Homework 3 Monday, March 9
Due Saturday, April 4, 11:59PM in Blackboard
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Objectives: To learn to define and implement classes and use classes and objects to manipulate data.
Tasks:
Read the entire document before start NetBeans.
Create a Java application project named BCS345hw3 which contains two public classes, BCS345hw3
and Student. The BCS345hw3 class serves as a driver program and the Student class defines fields
and methods about a student object.
Your program will read student’s ID, first name, last name, and 5 scores from an input file
hw3data.txt, calculate the average test score after the lowest test score is dropped, and then assign a
letter grade to student using the following grade scale:
90 <= average <= XXXXXXXXXXA
80 <= average < 90 B
70 <= average < 80 C
60 <= average < 70 D
0 <= average < 60 F
The program must output each student’s ID, full name, 5 scores, average, and letter grade in a neat format
similar to the sample output.
A. (40 points) Define the Student class and implement it as required. The Student class has the
following private instance fields.
No. Instance Fields Description
1 ID An int variable that holds a student’s ID.
2 firstName A string variable that holds a student’s first name.
3 lastName A string variable that holds a student’s last name.
4 scores An int a
ay that holds a student’s 5 test scores.
The Student class has the following public instance methods.
No. Instance Methods Description
1 No-arg constructor Sets ID to 0, firstName and lastName to “No Name”, and all
elements of scores to 0.
2 Overloaded constructor Accepts a student’s ID, first name, last name, and an int a
ay
(storing 5 scores) as arguments to set the fields of a Student object.
3 Copy constructor Uses the values of an existing Student object to create and instantiate
a new Student object.
4 setID Accepts an int argument and copies it into the ID instance field.
5 setFName Accepts a string argument and copies it into the firstName
field.
6 setLName Accepts a string argument and copies it into the lastName field.
7 setScores Accepts an int a
ay argument and copies it into the scores field.
8 getID Returns the value in ID.
9 getFName Returns the value in firstName.
10 getLName Returns the value in lastName.
11 getScores Returns an int a
ay that stores all 5 scores of a Student object.
12 getAverage Calculates the average test score after the lowest test score is dropped
and returns the average test score as a floating-point value. Precision
must be kept in the calculation.
13 getGrade Returns the letter grade based on the student’s average test score.
Hint: call the getAverage method to get the average score.
14 toString Output a student’s ID, first name, last name, 5 test scores, average
test score, and the letter grade. Format the output and set each field to
a fixed width.
B. (20 points) In the driver program, write statements to test your class implementation including all the
constructors and member methods.
C. (40 points) Suppose that the input data file contains the records of 25 students, in the driver program,
use an a
ay to manage 25 Student objects, read from the data file, instantiate the student objects,
process data, and output the results. Code efficiency must be taken into consideration.
The hw3data.txt file can be downloaded separately. Assume all the data are valid. The data file must
e placed directly in the project folder (at the same level of src folder) if file path is not provided.
Submission:
Submit your two source code files in Blackboard. The file name are case-sensitive and must be
BCS345hw3.java and Student.java. Use the default package for your project. Points will be
deducted for submission that doesn’t meet the name and package requirements.
Be sure to include the integrity statement I certify that this submission is my own original work with
your name and RAM ID in all your source files.
Sample output for part C:
10001 Alice Brown XXXXXXXXXX
10004 Bob Bush XXXXXXXXXX
10010 Carl Capra XXXXXXXXXX
10012 David Lieberman XXXXXXXXXX
10034 John Menchin XXXXXXXXXX
10056 George Smith XXXXXXXXXX
10062 Elaine Sanders XXXXXXXXXX
10078 Jack Cunningham XXXXXXXXXX
10090 Susie Brown XXXXXXXXXX
10099 Marvella Garcia XXXXXXXXXX
10120 Tony Peterson XXXXXXXXXX
10129 John Jones XXXXXXXXXX
10131 Mary Evans XXXXXXXXXX
10146 Nancy Drew XXXXXXXXXX
10152 Lola Zapeta XXXXXXXXXX
10155 Duckey Donald XXXXXXXXXX
10163 Goof Goofy XXXXXXXXXX
10168 Brave Balto XXXXXXXXXX
10178 Snow Smitn XXXXXXXXXX
10184 Alice Wonderful XXXXXXXXXX
10192 Samina Akthar XXXXXXXXXX
10207 Simba Green XXXXXXXXXX
10211 Donald Egger XXXXXXXXXX
10216 Brown Deer XXXXXXXXXX
10245 Johny Jackson XXXXXXXXXX