Here's the Student class:
public class Student {
private String lastName;
private String firstName;
private int studentId;
private double[] projects;
private double[] quizzes;
public Student(String lastName, String firstName, int studentId){
this.lastName=lastName;
this.firstName=firstName;
this.studentId=studentId;
projects = new double[] {-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0,
-1.0,-1.0, -1.0, -1.0, -1.0,};
quizzes = new double [] {-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0};
}
public boolean setProjectScore(double newProjects, int projectNumber) {
projects[projectNumber] = newProjects;
if (projectNumber >= 0 || projectNumber <= 14)
return true; else
return false;
}
public boolean setQuizScore(double newQuizzes, int quizNumber) {
quizzes[quizNumber] = newQuizzes;
if (quizNumber >= 0 || quizNumber <= 9)
return true; else
return false;
}
public double getProjectScore(int projectNumber){
if (projects[projectNumber] < 0 || projects[projectNumber] > 14)
return -1.0; else
return projects[projectNumber];
}
public double getQuizScore(int quizNumber){
if (quizzes[quizNumber] < 0 || quizzes[quizNumber] > 9)
return -1.0; else
return quizzes[quizNumber];
}
public int getNextProjectIndex(){
int nextProjectIndex=0;
while (nextProjectIndex <= 14)
if (projects[nextProjectIndex] == -1.0)
return nextProjectIndex;
nextProjectIndex++;
return -1;
}
public int getNextQuizIndex(){
int nextQuizIndex=0;
while (nextQuizIndex <= 9)
if (projects[nextQuizIndex] == -1.0)
return nextQuizIndex;
nextQuizIndex++;
return -1;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
}
And here is the tester class:
public class Main {
public static void main(String[] args) {
int i = 0;
int j = 0;
Student st = new Student("Braun", "Thiago", 1);
System.out.println("Student Last Name is:" + " " + st.getLastName());
System.out.println("Student First Name is:" + " " + st.getFirstName());
System.out.println("Student ID is:" + " " + st.getStudentId());
while (st.getProjectScore(st.getNextProjectIndex()) == -1.0){
st.setProjectScore (70.0, (st.getNextProjectIndex()));
}
while (st.getQuizScore(st.getNextQuizIndex()) == -1.0){
st.setQuizScore (85.0, (st.getNextQuizIndex()));
}
do {
System.out.println("Student Project Grades are:" + " " + st.getProjectScore(i));
i++;
} while (i <= 14);
do {
System.out.println("Student Quiz Grades are:" + " " + st.getQuizScore(j));
j++;
} while (j <= 9);
I think there are some logical mistakes on both while methods that I haven't been able to figure out. When i run the Main class I get the results below and the applet enters on an infinite loop with nothing showing on the console. Only way to quit is to press the stop button.
Student Last Name is: Braun
Student First Name is: Thiago
Student ID is: 1
Thanks again for any input!

New Topic/Question
Reply



MultiQuote



|