im working on this program and im getting really stuck. i was hoping to get it done soon, but it is dragging out. i have completed the first half of the instructions, i believe.
2. Create an abstract class called Student.
a. Student will need instance variables name , qz1, qz2, qz3, qz4, and
qz5 (of types String and int, respectively).
b. Student will need appropriate methods and constructors. To make things
interesting, create a getQuiz() method that takes in a quiz number as input and
then returns the appropriate quiz value. Likewise, setQuiz() will take as input
a quiz number and quiz score, and then put the value into the right variable. Make
sure to have a toString() method that prints the name of the Student along
with the quiz scores.
c. Save the class as Student.java.
im going about doing this with this code.
/* Student.java
Manage a student's name and five test scores.
*/
public class Student {
//Instance variables
//Each student object has a name and three test scores
private String name; //Student name
private int qz1; //Score on test 1
private int qz2; //Score on test 2
private int qz3; //Score on test 3
private int qz4; //Score on test 4
private int qz5; //Score on test 5
public Student(){
//Initialize a new student's name to the empty string and the test
//scores to zero.
name = "";
qz1 = 0;
qz2 = 0;
qz3 = 0;
qz4 = 0;
qz5 = 0;
}
//Other methods
public void setName (String nm){
//Set a student's name
name = nm;
}
public String getName (){
return name;
}
public void setQuiz (int i, int score){
//Set test i to score
if (i == 1) qz1 = score;
else if (i == 2) qz2 = score;
else if (i == 3) qz3 = score;
else if (i == 4) qz4 = score;
else if (i == 5) qz5 = score;
}
public int getQuiz (int i){
//Retrieve score i
if (i == 1) return qz1;
else if (i == 2) return qz2;
else if (i == 3) return qz3;
else if (i == 4) return qz4;
else if (i == 5) return qz5;
}
public String toString(){
String str;
str = "Name: " + name + "\n" + // "\n" denotes a newline
"Test 1: " + qz1 + "\n" +
"Test 2: " + qz2 + "\n" +
"Test 3: " + qz3 + "\n" +
"Test 4: " + qz4 + "\n" +
"Test 5: " + qz5 + "\n" +
return str;
}
}
}
like i said, i think this is right.
the trouble comes when i have to go about the second half of the assignment
3. You are to create a class called TestStudent and save it as TestStudent.java.
a. Make sure that you create an array called myClass. Add the following Students,
with their quiz scores:
Candidate Q1 Q2 Q3 Q4 Q5
Mark Kennedy 70 80 90 100 90
Max Gerard 80 85 90 85 80
Jean Smith 50 79 89 99 100
Betty Farm 85 80 85 88 89
Dilbert Gamma 70 70 90 70 80
b. Create a method called printBook() that traverses through the array and prints
out each element.
c. Create a method called replaceName() that replaces a Student’s name with a
new one.
d. Create a method called replaceQuiz() that replaces a Student’s quiz grade
with a new one. It should replace only one quiz grade as indicated when it is
called. It will have the array, quiz number, and quiz value as input.
e. Create a method called replaceStudent() that replaces a Student with
another one. It will have the array, name to replace, new Student name, and quiz
scores as input.
f. Create a method called insertStudent() that inserts a new Student before
another Student in the array. It will have the array, name to find, new Student
name, and quiz scores as input.
g. Create a method called deleteStudent() that finds a Student by name and
then deletes that Student.
im not really familiar with sorting and it is confusing me horribly. as i was just looking i realized realized that i need to make my qz an array list. im going to get to that. but if anyone has any help to offer it is appreciated.