Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

CONFIDENTIAL 3

QUESTION 2 (20 marks)

You have been tasked with developing an animal shelter management system for a local
animal shelter. The shelter needs a system to manage their animals, including name, age,
breed (eg: Belgian Shepherd) and availability for adoption.

a) Write a complete class definition for the object you identified in the above problem that
contains all attributes as mentioned above and the following methods.

 A normal constructor.
 Accessor methods for data members.
 A setAvailability(boolean available) method that receives a boolean value
and modifies the availability for adoption.
 An isAvailable() method that determines the availability for adoption by returning
true for available. Otherwise, it returns false.
 A toString() method that returns all data members of the class.
(10 marks)

b) Write a Java main program to perform the following tasks:

i) Create a new object and add the following information.

name - "Lucky"
age - 2
breed - "Labrador Retriever"
(2 marks)

ii) Set the availability of the first animal to true.


(1 mark)

iii) Create another object and add the following information.

name - "Milo"
age – 1
breed - "German Shepherd"
(2 marks)

iv) Set the availability of the second animal to false.


(1 mark)

v) Count and display the number of animals available for adoption in the shelter.
(2 marks)

vi) Calculate and display the average age of all animals in the shelter.
(2 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like