You are on page 1of 2

Computer Science I Unit 3 Lab #2 Part I: Public Interface Part II: Implementations Part III: Tester 35 points 35 points

20 points Comment heading: 10 points Bonus: 10 points

Lab Goal : The lab was designed to teach you how to design, comment, implement and test a class. Lab Description : Implement a class Student. A student has a name, a number of quizzes and a total quiz score. You will supply methods and instance fields. You will add statements to a provided tester class.

Part I: Public Interface


Create a file called Student.java. Using javadocs comments, create the public interface for the Student class. The Product class consists of the following constructors and methods. The description you should use for the javadocs comments is given, but this time you must determine the class and method definitions. You must use the @return and @param tags when needed. After creating the public interface, make sure Student.java is in its own folder and then execute the javadocs tool to create the HTML. Student class: Default constructor: Overloaded constructor: quiz Method getName Method addQuiz: Method getTotalScore: A student has a name, a number of quizzes and a total quiz score. The average quiz score can be calculated. Constructs a student with a name of John Doe, the number of quizzes is 0, and the total quiz score is 0. Constructs a student with a given name. Number of quizzes and total score are set to 0. Gets the name of the student. Adds a quiz with a specified score to the student record. Gets the current total quiz score for the student.

Method getAverageScore: Gets the current average quiz score for the student.

Part II: Implementations


Add instance fields name, numQuizzes and totalQuizScore to the Student class. Remember to use the private access specifier for each. Implement each of the methods from the public interface using the commented descriptions you produced in Part I.

Part III: Tester


Save StudentTester.java (available online Unit 3\Lab 2) to your H drive. Follow the commented instructions to create objects of the Student class and call methods. Required output: John Doe total quiz score: 0 Peter Jackson total quiz score is: 263 Peter Jackson average quiz score is: 87.0

BONUS
Fix the average. Right now, the average quiz score is losing the decimal value. In class, we have not discussed integer division or casting, which are both discussed in chapter 4. Using these concepts, fix the average so that it does not lose its decimal value. Also, when the average is printed, format the output so that it prints 2 digits after the decimal point (also from chapter 4). Corrected output: John Doe total quiz score: 0 Peter Jackson total quiz score is: 263 Peter Jackson average quiz score is: 87.67

You might also like