I hope its ok if I post questions about my error problems.
Here is my messed up program.
I am wondering if anyone could help me correct it by explaining and posting a correct script for the flawed coding sections.
prompt will be posted after my code.
** With my code I dont know how to fix it so that my average score becomes 95.8333 rather than 97.
public class Student
{
private int quiz;
private double quizNum;
private
String name;
public Student(String n)
{
name = n;
}
public String getName()
{
return name;
}
public double getAverageScore()
{
return quizNum;
}
public void addQuiz(double scores)
{
quizNum = scores;
scores = (quiz + quiz + quiz)/3;
}
}
public class StudentRunner
{
public static void main(String[] args)
{
Student s = new Student("I Fail at Java");
s.addQuiz(100);
s.addQuiz(90.5);
s.addQuiz(97);
System.out.println("Name: "+s.getName());
System.out.println("Quiz average is " +s.getAverageScore());
}
}
Implement a class Student. A student is composed of a name, a total of all the quiz
scores they have taken, and the number of quizzes taken. Supply an appropriate
constructor and methods getName(), addQuiz(double score), and
getAverageScore(). Your client program should contain the following code:
Student s = new Student("Mary Ott");
s.addQuiz(100);
s.addQuiz(90.5);
s.addQuiz(97);
System.out.println("Name: " + s.getName());
System.out.println("Quiz average is " + s.getAverageScore());