Question

Implement a class Student. For the purpose of this exercise the student has a name and...

Implement a class Student. For the purpose of this exercise the student has a name and a total quiz score. The appropriate constructors and methods are: getName(), addQuiz(int Score), getTotalScore(), getAverageScore(). Include a toString that prints the students name, the quiz average and the number of quizzes taken. Override the equals method in a meaningful way. You must compare more than one variable in the equals method.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi Please Refer the below Code .I have commented the code properly and attached the snapshot of output code follows exactly same design as per question .Please refer Code:-

Code:--

---------

public class Student {

// declaring the variable

public String name;

public int totalScore;

public int numOfQuizz;

// default constructor

public Student(){

}

double average=0.0;

// parameterized constructor

public Student(String name, int totalScore, int numOfQuizz) {

super();

this.name = name;

this.totalScore = totalScore;

this.numOfQuizz = numOfQuizz;

}

// get name method as per problem

public String getName() {

return name;

}

// get total score method

public int getTotalQuizScore() {

return totalScore;

}

// get average score method as per problem statement

public double getaverageScore(){

average = totalScore/numOfQuizz;

return average;

}

// implementation of to string

@Override

public String toString() {

//return "Student [name=" + name + ", totalScore=" + totalScore + ", numOfQuizz=" + numOfQuizz + "]";

System.out.println("Name of Student is " + name + " Total Score of Quiz " + totalScore + " Number of quizzs taken " + numOfQuizz + " Average Score of Quizz " + average );

return null;

}

// overriding the equals method

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Student other = (Student) obj;

if (name == null) {

if (other.name != null)

return false;

} else if (!name.equals(other.name))

return false;

if (numOfQuizz != other.numOfQuizz)

return false;

if (totalScore != other.totalScore)

return false;

return true;

}

public void setName(String name) {

this.name = name;

}

public void addQuiz(int quizScore) {

this.totalScore = quizScore;

}

// testing through driver code

public static void main(String[] args) {

Student st = new Student("David", 500, 4);

st.getName();

st.getTotalQuizScore();

st.getaverageScore();

st.toString();

}

}

---------------------

Snapshot of Code and Output:-

------------------

Practice Project- Java - CheggNov/src/Student.java - Eclipse Ele Edit Source Refactor Navigate Search Projec Bun Window HelpPractice Project- Java - CheggNov/src/Student.java - Eclipse Ele Edit Source Refactor Navigate Search Projec Bun Window Help3ฏิ Practice-Project-Java-CheggNov/src/Student.java-Eclipse Ele Edit Source Refactor Navigate Search Projec Bun Window Help QPractice Project- Java - CheggNov/src/Student.java - Eclipse Ele Edit Source Refactor Navigate Search Projec Bun Window Help

In case of any doubt ant query please let me know in comment Section i would be happy to help you. Thanks.

Add a comment
Know the answer?
Add Answer to:
Implement a class Student. For the purpose of this exercise the student has a name and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • By Python 3 please 2. (a) Implement a class Student. For the purpose of this exercise,...

    By Python 3 please 2. (a) Implement a class Student. For the purpose of this exercise, a student has a name and a total quiz score. Supply an appropriate constructor and methods get Name, addQuiz(score), getTotalScore(), and getAverageScore(). To compute the latter, you also need to store the number of quizzes that the student took. (b) Modify the Student class to compute grade point averages. Methods are needed to add a grade and get the current GPA. Specify grades as...

  • Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The...

    Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The clone method must allow a deep copy on the students field. In addition, add the equals(Object o) and the toString() methods. Write a test program to invoke the compareTo, clone, equals, and toString methods in a meaningful way. Below is the Listing from the book that needs to be rewritten public class Course {    private String courseName;    private String[] students = new...

  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

  • JAVA Create a Java project to implement a simple Name class. This class will have the...

    JAVA Create a Java project to implement a simple Name class. This class will have the following class variable: First Name, Middle Name, Last Name, and Full Name Create the accessor/getter and mutator/setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Create a main() method to test your project.

  • Student class: Instance variables name id Constructors: Default constructor Constructor that has id and name passed...

    Student class: Instance variables name id Constructors: Default constructor Constructor that has id and name passed to the constructor Methods: Accessors int getID( ) String getName( ) Class Roster: This class will implement the functionality of all roster for school. Instance Variables a final int MAX_NUM representing the maximum number of students allowed on the roster an ArrayList storing students Constructors a default constructor should initialize the list to empty strings a single parameter constructor that takes an ArrayList<Student> Both...

  • Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman...

    Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...

  • Write an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student...

    Write an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student and “PostGraduate” that inherits form “Graduate”. Write the class definition for the abstract class “Student”. The class definition should include private instance variables of type String to hold the student’s first name, a string for his/her major and an int to hold the number of units taken. Getter and setter methods for each of the variables should be included in the class definition. Also...

  • Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties:...

    Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties: • StudentID • First Name • Last Name Class Student should have read/write properties, constructor(s) and should implement the Academic interface. For academic methods, return zero for average, zero for credits and false for graduate. Also implement the toString() method that returns the above information as a String. Part II (5%) [File: Academic.java] Create an interface Academic that declares three methods: 1. average -...

  • please use java do what u can 1. Modify the Student class presented to you as...

    please use java do what u can 1. Modify the Student class presented to you as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to be initially zero. Provide a method called set Test Score that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called get...

  • For the code below write a public static main() method in class Student that: - creates...

    For the code below write a public static main() method in class Student that: - creates an ArrayList<Student> object called students - adds 4 new Student objects to the students list, with some made up names and dates - sort the students list by name and display the sorted collection to System.out. use function getCompByName() - sort the students list by enrollment date and display the sorted collection to System.out. use function getCompByDate() import java.util.Comparator;    import java.util.Date;    public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT