File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JavaFX and the fly likes Java Programming Help? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Java Programming Help?" Watch "Java Programming Help?" New topic
Author

Java Programming Help?

Johny Do
Greenhorn

Joined: Oct 07, 2009
Posts: 1
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());


Philippe Lhoste
Greenhorn

Joined: Oct 23, 2009
Posts: 28
You are in a JavaFX section, not a Java one...

But being a kind soul, I will help a bit. Look at your method:

quizNum is equals to the last given value (last call of the method), you sum three times a variable that never changes, and at the end, modify a parameter which is lost on the next line.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Programming Help?
 
Similar Threads
Compile error
Confused with file read
Array returning last value entered
Help with toString message
grade program