Question
Need some help figuring this out From the starting projects for labs and homeworkLabs folder on Lamont, copy Lab8 and paste the copy in your
Need some help figuring this out
From the starting projects for labs and homework\Labs folder on Lamont, copy Lab8 and paste the copy in your H:\Personal\Cosc1010\Labs folder. Open the project with BlueJ.
The Grades project is composed of 3 classes: Student, GradeBook, and TestGradeBook.
The Student class represents a single student by storing his name and an array of his grades. This class is finished, DON'T MAKE ANY CHANGES TO THE STUDENT CLASS.
The GradeBook class has an ArrayList of Students. It will be able to add students to the list and print out all students and their grades. It is partially written.
The TestGradeBook class will be used to test the other 2 classes. It will create a GradeBook. It will then create a number of students and add them to the GradeBook. Finally it will print out all of the students. TestGradeBook is also unfinished.
Read the comments in the source code of the classes and finish writing them according to those instructions.
If you finish during lab, upload your code to your labs folder on Lamont and have it checked by your TA. If you don't finish during lab that's okay. Finish the lab before your next lab, have it checked during your TA's office hours and upload it to Lamont.
TestGradeBook
import java.util.ArrayList;
/** * Test class for GradeBook. * * @author Derek Green * @version October 30, 2006 */ public class TestGradeBook { private final String[] testNames = {"Andy", "Bill", "Chad", "Dave"}; private final int numberOfGrades = 10; private GradeBook gradeBook;
/** * Initializes the GradeBook by filling it with test data. */ /* Write a constructor method. In the method initialize the gradeBook field. Write a for loop that will loop once for each of the names in the "testNames" array. Each time through the loop create a new integer array of size "numberOfGrades" and use a loop to fill it with "numberOfGrades" random numbers between 10 and 99. Create a new student using this array for his grades and the correct testNames value for his name. Add this student to the gradeBook object.
Note: If I change numberOfGrades to a new value and/or add more names to the testNames array, your program should continue to function properly without any other modifications. */
/** * Prints the gradebook. */ /*Add a method that prints out the contents of the gradeBook.*/
}
GradeBook
import java.util.ArrayList; /** * A gradebook that keeps track of a list of students and can print out all students with their grades. * * @author Derek Green * @version October 30, 2006 */ public class GradeBook { //Add a flexible collection (i.e., an ArrayList of Students) field to hold a collection of Student objects. /** * Constructor for objects of class GradeBook */ /** * Add a single student to the list. */ /* Write a method called "addStudent" that takes a single parameter of type Student and adds it to the students collection. */ /** * Print out the contents of the gradebook. */ /* Write a method called "printGradeBook()". For each student in the student list, print the student's name and his grades. Each student should be printed on a separate line. */ }
Student
// DO NOT ALTER THIS CLASS
/** * A single student with a name and an integer array of grades. * * @author Derek Green * @version April 5, 2004 */ public class Student { private String name; private int[] grades;
/** * Constructor sets name and array of grades. */ public Student(String name, int[] grades) { this.name = name; this.grades = grades; } /** * Returns name. */ public String getName() { return name; } /** * Returns grades array. */ public int[] getGrades() { return grades; } public String toString() { String studentString = name + " "; for(int index = 0; index < grades.length; index++) { studentString += grades[index] + " "; } return(studentString); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started