Students Average Constructor coderinme

Students Average Constructor coderinme

Implement a Student class with the following fields, constructors and methods :
Fields:
name; totalScore; numberOfQuizzes;
Constructors:
public Student(String name, double score)
public Student(double score, String name)
public Student(String name) {
Methods:
public String getName()
public double getAverage() //this should return zero if no quiz has been take
public double getTotalScore()
Problem:

import java.io.*;
class Student
{
String name;
double totalScore;
int numberOfQuizzes;
public Student(String name,double Score)
{
this.name=name;
totalScore=Score;
}
public Student(double score,String name)
{
this.name=name;
totalScore=score;
}
public Student(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public double getAverage()
{
double avg=totalScore/numberOfQuizzes;
return avg;
}
public double getTotalScore()
{
return totalScore;
}
public void addQuiz(double score)
{
totalScore+=score;
numberOfQuizzes++;
}
public void printStudent()
{
System.out.println( "\nStudent "+name+" ,Average :"+getAverage());
}
public String toString() {
return "\nStudent "+name+" ,Average :"+getAverage();
}
}
public class Q30
{
public static void main(String[] args) throws IOException
{
BufferedReader stdin=new BufferedReader( new InputStreamReader(System.in));
System.out.print("Enter student name :");
String name=stdin.readLine();
Student student1=new Student(name);
for(int i=1;i<=3;i++) {
System.out.print("Enter quiz #"+i+" for "+name+" :");
double score=Double.parseDouble(stdin.readLine());
student1.addQuiz(score);
}
student1.printStudent();
}
}

For more programs on Java, visit our Java Archives

Students Average Constructor

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.