- Purpose - to demonstrate the use of Java classes and data encapsulation.
- Objective - to create a
Classroom
which manipulates a compositeList
ofStudent
objects which contain data detailing theirfirstName
,lastName
, andexamScores
. - Restrictions - Ensure positive and negative unit tests exist per feature of the application
- Create a class
Student
.
- Declare an instance variable for each of the previously mentioned properties:
String firstName
- a collection of characters representative of a first name.
String lastName
- a collection of characters representative of a last name.
ArrayList<Double> examScores
- a dynamic collection of decimal values representative of test scores.
- Define a
Student
constructor whose parameters are used to initalize its instance variables. - The
Student
constructor has expected parameters ofString
representative of afirstName
String
representative of alastName
Double[]
representative of a collection oftestScores
- Getters and Setters
- Define a getter and setter for each of the instance variables declared in the
Student
class.
- Define a getter and setter for each of the instance variables declared in the
- Define method
getExamScores()
-
Student
should define a method which returns a string representation of all exams taken.-
Sample Script:
// : Given String firstName = "Leon"; String lastName = "Hunter"; Double[] examScores = { 100.0, 95.0, 123.0, 96.0 }; Student student = new Student(firstName, lastName, examScores); // When String output = student.getExamScores(); // Then System.out.println(output);
-
Sample Output
Exam Scores: Exam 1 -> 100 Exam 2 -> 95 Exam 3 -> 123 Exam 4 -> 96
-
-
- Define method
addExamScore(double examScore)
-
Student
should define a method namedaddExamScore
which uses adouble
parameter to add anexamScore
to its composite ListexamScores
.-
Sample Script:
// : Given String firstName = "Leon"; String lastName = "Hunter"; Double[] examScores = { }; Student student = new Student(firstName, lastName, examScores); // When student.addExamScore(100.0); String output = student.getExamScores(); // Then System.out.println(output);
-
Sample Output
Exam Scores: Exam 1 -> 100
-
-
- Define method
setExamScore(int examNumber, double newScore)
-
Student
should define a method namedsetExamScore
which uses anint
parameter to identify an exam in the list, and adouble
parameter to re-assign the respective value.-
Sample Script:
// : Given String firstName = "Leon"; String lastName = "Hunter"; Double[] examScores = { 100.0 }; Student student = new Student(firstName, lastName, examScores); // When student.setExamScore(1, 150.0); String output = student.getExamScores(); // Then System.out.println(output);
-
Sample Output
Exam Scores: Exam 1 -> 150
-
-
- Define method
getAverageExamScore()
-
Student
should define a method namedgetAverageExamScore()
which returns the sum of theexamScore
list divided by itssize
.-
Sample Script:
// : Given String firstName = "Leon"; String lastName = "Hunter"; Double[] examScores = { 100.0, 150.0, 250.0, 0.0 }; Student student = new Student(firstName, lastName, examScores); // When Double output = student.getAverageExamScore(); // Then System.out.println(output);
-
Sample Output
125.0
-
-
- Define method
toString()
-
Student
should override thetoString
method by returning a cleanString
representation of the person.-
Sample Script:
// : Given String firstName = "Leon"; String lastName = "Hunter"; Double[] examScores = { 100.0, 150.0, 250.0, 0.0 }; Student student = new Student(firstName, lastName, examScores); // When String output = student.toString(); // Then System.out.println(output);
-
Sample Output
Student Name: Leon Hunter > Average Score: 125 > Exam Scores: Exam 1 -> 100 Exam 2 -> 150 Exam 3 -> 250 Exam 4 -> 0
-
-
- Create a class
Classroom
- Declare an instance variable for each of the
Classroom
properties:Student[] students
- a collection of student objects
-
Define a
Classroom
constructor whose parameters are used to initalize its instance variable. The classClassroom
should support 3 different ways of being constructed.-
The class
Classroom
should define a constructor which takes an argument of anint
representative of themaxNumberOfStudents
that thisClassroom
can hold. -
The class
Classroom
should define an additional constructor which takes an argument ofStudent[]
representative of the collection ofStudent
objects thisClassroom
will store. -
The class
Classroom
should define a nullary constructor which initializes the compositestudents
object to be an empty array of 30Student
objects.
-
- Define method
getStudents()
- Define a getter which returns the composite
students
object.
- Define a getter which returns the composite
- Define method
getAverageExamScore()
-
Define a getter which returns the sum of all exam averages divided by the number of students.
-
Sample Script:
// : Given Double[] s1Scores = { 100.0, 150.0 }; Double[] s2Scores = { 225.0, 25.0 }; Student s1 = new Student("student", "one", s1Scores); Student s2 = new Student("student", "two", s2Scores); Student[] students = {s1,s2}; Classroom classroom = new Classroom(students); // When double output = classroom.getAverageExamScore(); // Then System.out.println(output);
-
Sample Output
125.0
-
-
- Define method
addStudent(Student student)
-
Define a method which uses a
Student
parameter to add aStudent
object to the compositestudents
list.-
Sample Script:
// : Given int maxNumberOfStudents = 1; Classroom classroom = new Classroom(maxNumberOfStudents); Double[] examScores = { 100.0, 150.0, 250.0, 0.0 }; Student student = new Student("Leon", "Hunter", examScores); // When Student[] preEnrollment = classroom.getStudents(); classroom.addStudent(student); Student[] postEnrollment = classroom.getStudents(); // Then String preEnrollmentAsString = Arrays.toString(preEnrollment); String postEnrollmentAsString = Arrays.toString(postEnrollment); System.out.println("==========================="); System.out.println(preEnrollmentAsString); System.out.println("==========================="); System.out.println(postEnrollmentAsString);
-
Sample Output
=========================== [] =========================== [Student Name: Leon Hunter > Average Score: 125 > Exam Scores: Exam 1 -> 100 Exam 2 -> 150 Exam 3 -> 250 Exam 4 -> 0]
-
-
- Define method
removeStudent(String firstName, String lastName)
- The class
Classroom
should define a method which uses afirstName
andlastName
parameter to identify and remove the respective student from compositestudents
object. - Ensure the array is re-ordered after the removal; Null values should be located in the final indices of the array.
- The class
- Define method
getStudentsByScore()
- The class
Classroom
should define a methodgetStudentsByScore()
which returns an array representation ofStudent
objects sorted in descending order by score. - If two students have the same class average, order them lexigraphically.
- The class
- Define method
getGradeBook()
- The class
Classroom
should define a methodgetGradeBook()
which returns a mapping ofStudent
objects to a respective letter grade determined by creating a grading curve such that- An
A
is awarded to students whose class average is in the upper 10th percentile. - A
B
is awarded to students whose class average falls between the upper 11th and 29th percentile. - A
C
is awarded to students whose class average falls between the upper 30th and 50th percentile. - A
D
is awarded to students whose class average falls between the lower 51st and 89th percentile. - An
F
is awarded to students whose class average is in the lower 11th percentile.
- An
- The class