*p3.6

From GGCWiki
Jump to: navigation, search

p3.6

  • I need to work on this a little more, but it does what the problem describe, but I did it in an unconventional (probably wrong) way.


  • I like the logic behind this, I can't test it but I can see from the code that you might need to return the number of quizes someting like : System.out.println("Student 1: " + student1.getName() + " Score: " + student1.getScore + " Number of Quizzes taken: " student1.numberQuizzes());

student1.addQuiz(1);

package assignments;

public class Student {

    private String name;
    private int score;
    private int averageScore;
    private int numberQuizzes = 0;
    
   



	
	public Student(String name, int score)
	{
		this.name = name;
		this.score =score;
	}
	
	public String getName()
	{
		return name;
	}
	public int getScore()
	{
		return score;
	}
	
	public int addQuiz(int num)
	{
		numberQuizzes = numberQuizzes +num;
		return numberQuizzes;
	}
	


	
	public int getNumQuiz()
	{
		return numberQuizzes;
	}
	

	
	public int setTotalScore()
	{ 
		int totalScore = 0;
		totalScore = getScore() + totalScore;
		return totalScore;
		
	}


	

	
	public int getAverageScore(int scoreT, int num)
	{
		averageScore = scoreT / num;
		return averageScore;
	}
		
	
	public static void main(String[] args) 
	{

		Student student1;
		student1 = new Student("Bob",80);
		Student student2;
		student2 =new Student("Greg",70);

		Student average;
		average = new Student("Average", student1.getScore() + student2.getScore());
		
	System.out.println("Student 1: " + student1.getName() + " Score: " + student1.getScore());
	student1.addQuiz(1);
	System.out.println("Student 2: " + student2.getName() + " Score: " + student2.getScore());
	student2.addQuiz(1);
	//System.out.println(student1.setTotalScore());
	//System.out.println(student2.setTotalScore());
	//System.out.println(student1.getAverageScore());
	//System.out.println(getAverageScore(student1.getScore(), student2.getScore()));
	System.out.println("Score Average: " + average.getAverageScore(average.getScore(), 2));
	
	
	

		
	
		
		
		
	
		
		
	}
}
Personal tools