Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.tools.javac.util.ArrayUtils;
- import java.rmi.StubNotFoundException;
- /**
- * Created by greg on 4/13/15.
- */
- public class TestStudent {
- //Initialized list of students named myClass
- private Student[] myClass = {new Student("Mark Kennedy", 70, 80, 90, 100, 90), new Student("Max Gerard", 80, 85, 90, 85, 80), new Student("Jean Smith", 50, 79, 89, 99, 100), new Student("Betty Farm", 85, 80, 85, 88, 89), new Student("Dilbert Gamma", 70, 70, 90, 70, 80)};
- /**
- * Returns the list of students' names along with their quiz scores
- *
- * @return String value of students' names along with their quiz scores
- */
- public String printBook() {
- String output = ""; //Initializes variable output
- for (int i = 0; i < myClass.length; i++) //Goes through the list of students myClass
- output = output + myClass[i] + " "; //Adds the students string value to output, along with a space.
- output = output.trim(); //Trims the additional space from the final string
- return output; //Returns output
- }
- /**
- * Replaces the name of a student with a new name
- *
- * @param nameToReplace Name of student to get their name replaced
- * @param newName New name to replace the old with
- */
- public void replaceName(String nameToReplace, String newName) {
- for (int i = 0; i < myClass.length; i++) //Goes through the list of students myClass
- if (myClass[i].name == nameToReplace) //Checks if the student has the name requested to replace
- myClass[i].name = newName; //Sets the students name to the new name
- }
- /**
- * Replaces a students quiz score
- *
- * @param studentName Name of student to have their quiz score changed
- * @param quizNumber Quiz number to be changed, 1-5
- * @param quizValue Score recieved on quiz
- */
- public void replaceQuiz(String studentName, int quizNumber, int quizValue) {
- for (int i = 0; i < myClass.length; i++) //Goes through the list of students myClass
- if (myClass[i].name == studentName) //Checks if the student has the name requested to modify
- myClass[i].setQuiz(quizNumber, quizValue); //Sets the students quiz score requested to be changed to the given value
- }
- /**
- * Replaces a student with an entirely new student
- *
- * @param studentName Name of student to replace
- * @param newName Name of the new student
- * @param q1 Quiz 1 Score
- * @param q2 Quiz 2 Score
- * @param q3 Quiz 3 Score
- * @param q4 Quiz 4 Score
- * @param q5 Quiz 5 Score
- */
- public void replaceStudent(String studentName, String newName, int q1, int q2, int q3, int q4, int q5) {
- Student newStudent = new Student(newName, q1, q2, q3, q4, q5); //Creates a new student "newStudent" with the given values
- for (int i = 0; i < myClass.length; i++) //Goes through the list of students myClass
- if (myClass[i].name == studentName) //Checks if the student has the name requested to replace
- myClass[i] = newStudent; //Set the spot on the array to the new student with the given values
- }
- /**
- * Inserts a student in front of the given student on the list
- *
- * @param studentName Name of the student the new student will be inserted in front of
- * @param newName Name of the new student to be inserted
- * @param q1 Quiz 1 Score
- * @param q2 Quiz 2 Score
- * @param q3 Quiz 3 Score
- * @param q4 Quiz 4 Score
- * @param q5 Quiz 5 Score
- */
- public void insertStudent(String studentName, String newName, int q1, int q2, int q3, int q4, int q5) {
- Student newStudent = new Student(newName, q1, q2, q3, q4, q5); //Creates the new student using the given values
- Student[] tempClass = new Student[myClass.length + 1];
- boolean t = false;
- for (int i = 0; i < myClass.length; i++)
- if (!myClass[i].name.equals(studentName) && !t)
- tempClass[i] = myClass[i];
- else if (myClass[i].name.equals(studentName)) {
- t = true;
- tempClass[i] = newStudent;
- } else if (t)
- tempClass[i] = myClass[i - 1];
- tempClass[tempClass.length - 1] = myClass[myClass.length - 1];
- myClass = tempClass;
- }
- /**
- * Deletes a student
- *
- * @param studentName Student name to be deleted
- */
- public void deleteStudent(String studentName) {
- Student[] tempClass = new Student[myClass.length - 1];
- boolean t = false;
- for (int i = 0; i < myClass.length; i++)
- if (!myClass[i].name.equals(studentName) && !t)
- tempClass[i] = myClass[i];
- else if (myClass[i].name.equals(studentName)) {
- t = true;
- } else if (t)
- tempClass[i - 1] = myClass[i];
- myClass = tempClass;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement