Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java. Please help with my Tester, I am having a hard time understanding how to create this. Thank you. Assignment: Write a class called Student

Java. Please help with my Tester, I am having a hard time understanding how to create this. Thank you.

Assignment:

  1. Write a class called Student.
    1. The class has 3 Instance variables
      1. name - a String of the student's full name
      2. totalQuizScore - double
      3. numQuizesTaken - int
    2. Constructor
      1. Default constructor that sets the instance fields to a default value
      2. Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value.
    3. Methods
      1. setName - sets or changes the student name by taking in a parameter
      2. getName - returns the name of the student
      3. getAverageScore - calculates and returns the average quiz score.
      4. addQuiz
        1. takes in a score parameter (int)
          1. If the score parameter is not within the range of a score (0 >= score <= 100) Display an error message and ignore that score.
          2. adds that score to totalQuizScore
          3. increments the numQuizesTaken field.
      5. getTotalQuizScore - returns the totalQuizScore .

  1. Write another class that will test our Student class called StudentTester
    1. Prompts the user for Student name(Hint: Scanner next() method)
    2. Creates a Student object with that name
    3. Create a loop that
      1. Asks user for a quiz score
      2. Adds that score to the Student object
      3. Ask the user if they are finished entering scores
    4. Use the methods of the class to print out the student's name, total score and average quiz score in a nicely formatted output where the score is rounded to 2 decimal place. (Hint use printf)
    5. Create new student object using the default constructor.
    6. Use the appropriate method to set the new Student object student name.
    7. Use the appropriate method to print out the new student's name.

My code for Student:

public class Student { /** * 3 Instance variables: name - a String of the student's full name; * totalQuizScore - double; numQuizesTaken - int */ private String name; private double totalQuizScore; private int numQuizesTaken; /** * Default constructor that sets the instance fields to a default value */ public Student() { this.name = " "; this.setTotalQuizScore(0); this.setNumQuizesTaken(0); } /** * Parameterized constructor; sets the name instance field to a parameter * value and set the other instance fields to a default value. */ public Student(String name) { this.name = name; this.setTotalQuizScore(0); this.setNumQuizesTaken(0); } /** * Methods */ /** * setName - sets or changes the student name by taking in a parameter */ public void setName(String name) { this.name = name; } /** * getName - returns the name of the student */ public String getName() { return name; } /** * getAverageScore - calculates and returns the average quiz score. */ public double getAverageScore() { return getAverageScore(); } /** * addQuiz; takes in a score parameter (int) * If the score parameter is not within the range of a score * (0 >= score <= 100) Display an error message and ignore that score. * adds that score to totalQuizScore * increments the numQuizesTaken field. * @return */ public void addQuiz(int score) { if((score >= 0) && (score <= 100)) { this.totalQuizScore += score; this.numQuizesTaken++; } System.out.println("There is an error"); System.exit(0); }

/** * getTotalQuizScore - returns the totalQuizScore . * @return */ public double getTotalQuizScore() { return totalQuizScore; }

public void setTotalQuizScore(double totalQuizScore) { this.totalQuizScore = totalQuizScore; }

public int getNumQuizesTaken() { return numQuizesTaken; }

public void setNumQuizesTaken(int numQuizesTaken) { this.numQuizesTaken = numQuizesTaken; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions