java - How can I count how many addQuiz I have used and use that to get an average score? -



java - How can I count how many addQuiz I have used and use that to get an average score? -

i working on assignment create programme create class student. name, , total quiz score, add together quiz score, , average quiz score.

public class pupil { private final string name; private int totalquizscore; public student(string studentname, int initialscore) //constructor students name , total score { name = studentname; totalquizscore = initialscore; } //returns name of new pupil public string getname() { homecoming name; } //adds quiz score total quiz scores public int addquiz(int score) { totalquizscore = totalquizscore + score; homecoming totalquizscore; } //returns total quiz score public int gettotalscore() { homecoming totalquizscore; } }

here main

public class studentgrade { public static void main(string[] args) { pupil tim = new student("johnson, tim", 0); //new pupil name tim johnson, initial score of 0; tim.getname(); //returns name tim.addquiz(9); //add quiz score of 9 tim.addquiz(10); //add quiz score of 10 tim.addquiz(10); //add quiz score of 10 tim.gettotalscore();//returns total of scores string name = tim.getname(); //save pupil name variable name int totalscore = tim.gettotalscore(); //save pupil total quiz scores in variable totalscore system.out.println(name + " " + totalscore); } }

i need figure average score quizes added. need able count how many quizzes added...this i'm having issues.

create variable count increments every time phone call addquiz();

private int count; //initialize 0 in constructor public int addquiz(int score) { totalquizscore = totalquizscore + score; ++count; homecoming totalquizscore; }

now calculating average trivial matter of dividing totalquizscore count.

java

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -