• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Programming Help?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());


 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic