Introduction to Computer Science for majors II by James Tam

Return to the course web page

CPSC 233: Mini-Assignment #2

Due Jan 31 at 4 PM

New Concepts to be applied for the assignment

Aside from the 'main' method you are not to write static methods for this assignment. (If you don't know what I'm referring to by static methods, I will be discussing this topic later in the course). Your program must consist of three classes (as described below). If you do implement other static methods then you will receive few, if any, marks for features listed below.

Description

  • Defines a class 'Cat' (9 marks)
 
  •  Attributes: name (String) and age (numeric) (2 marks)
 
  • Methods:
     
  • A no argument constructor that sets the name and age attributes to obvious default starting values (e.g., "no name" for the name and -1 for the age) (2 marks)
  • Accessor 'get()' methods for the name and age attributes (2 marks)
  • Mutator 'set()' methods for the name and age attributes (2 marks)
  • A 'makeSound()' method that displays the message 'meow' onscreen when called (1 mark)
     
     
     
  • Defines a class 'Dog' (9 marks)
 
  •  Attributes: name (String) and age (numeric) (2 marks)
 
  • Methods:
     
  • A no argument constructor that sets the name and age attribute to obvious default starting values (e.g., "no name" for the name and -1 for the age) (2 marks)
  •  Accessor 'get()' methods for the name and age attributes (2 marks)
  •  Mutator 'set()' methods for the name and age attributes (2 marks)
  •  A 'makeSound()' method that displays the message 'bark' onscreen when called (1 mark)
     
     
     
  • Defines the 'Driver' class. The 'main()' method will contain the following instructions (10 marks)
 
  • Instantiates instances of a dog and cat (2 marks)
  • Displays the name and age attributes of the dog onscreen, the default values should appear (2 marks)
  • Displays the name and age attributes of the cat onscreen, the default values should appear (2 marks)
  • Sets the age and name of the cat to 7 and 'Tigger' respectively (2 marks)
  • Displays the name and age attributes of the cat onscreen, the new values should appear (2 marks)

Marking key

Marks earned 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Grade point 4.0 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0 2.9 2.8 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.8 1.6 1.4 1.2 1 0.8 0.6 0.0

Submitting your work:

  1. Assignments (source code/'dot-java' file) must be electronically submitted according to [the assignment submission requirements].
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].

External libraries that can be used (unless otherwise you can not assume that you can use the library).

  1. You cannot use methods other than the ones for output: printf(), print(), println().