 |
CS 111 - Introduction to Computer Science
Homework #4 |
Due: Friday 9/25 at the beginning of class
1. Definitions: In your own words, define the following terms:
- class
- object
- method
- constructor
- instance variable (a.k.a field)
2. Date: Exercise 3.15. Submit both Date.java and
DateTest.java.
3. Circle: Create a class Circle with
- a constructor that takes a radius,
- getRadius and setRadius methods,
- a getArea method, and
- a getCircumference method.
Also write a test program called CircleTest.java that creates two Circle objects and prints out
their area and circumference. Use double values throughout.
4. Student: Create a class Student with
- a constructor that takes a String name,
- a getName method that returns the Student name,
- an addQuiz method that allows an int quiz score to be
added to the student's quiz total,
- a getQuizTotal method that returns the total int score of all quizzes that have been added, and
- a getQuizAverage method that returns the average double quiz score so far.
Hint: You'll need to keep track of how many quizzes have been added.
Also write a test program StudentTest.java that
- has the user input a name,
- constructs a Student object,
- has the user enter three int quiz scores, adding each separately to the Student object
using the addQuiz(int) method, and
- prints "Student <name> has a total score of <quiz total> and an average
score of <quiz average>."
Note: The constructor should only take name
information. Quiz scores are only added through the addQuiz
method.