Your program must consist of three classes (as described below).
- Defines a class 'Cat' (9 marks)
|
|
-
Attributes: name
(String) and age
(numeric) (2 marks)
|
|
|
|
|
|
- An "init()" 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: one
method will return the name, one method will return the age back to
the caller of the method (2 marks)
- Mutator 'set()' methods: a method
that takes one argument in addition to the 'self'
parameter. The value of that argument will be used to set the value
of an attribute. There should be one set method for each attribute.
(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)
|
|
|
|
|
|
-
An "init()"
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: one method will return the name, one method will return the
age back to the caller of the method
(2 marks)
-
Mutator 'set()' methods: a method that
takes one argument in addition to the 'self'
parameter. The value of that argument will be used to set the value
of an attribute. There should be one set method for each attribute.
(2 marks)
- A 'makeSound()' method that
displays the message 'bark' onscreen when called (1 mark)
|
|
|
|
|
|
|
|
|
|
- Defines the 'Driver' class. The 'main()/driver()'
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)
|