0% found this document useful (0 votes)
3 views2 pages

Object-Oriented Programming in Games

The document outlines a programming task involving the creation of a computer game with event management using object-oriented programming. It includes instructions for declaring classes, constructors, and methods for handling events and vehicles, specifically focusing on the EventItem and Vehicle classes. Additionally, it requires implementing user interaction for entering vehicle details and displaying event information.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Object-Oriented Programming in Games

The document outlines a programming task involving the creation of a computer game with event management using object-oriented programming. It includes instructions for declaring classes, constructors, and methods for handling events and vehicles, specifically focusing on the EventItem and Vehicle classes. Additionally, it requires implementing user interaction for entering vehicle details and displaying event information.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical One

Q1] A computer game is designed for users to select characters. Each character can take part in a group of
events. Each group has five events. There are four types of event: jump, swim, run, drive.
The program is written using object-oriented programming.
(a) The class EventItem stores data about the events.

(i) Write program code to declare the class EventItem and its constructor. Do not declare the other methods.
Use your programming language’s appropriate constructor. All attributes must be private.
(ii) The get methods GetName(), GetDifficulty() and GetEventType() each return the relevant attribute.
Write program code for the three get methods.
(b) The array Group stores five objects of type EventItem.
(i) Write program code to declare Group local to the main program.
(ii) One group has the following events:

Write program code to create an instance of EventItem for each of the five events, and store them in Group.
(iii) There are three more methods that should have been in the class namely:
- ShowName , that will display the name of the event
- ShowType, that will display the type of event
- ShowDifficulty, that will display the difficulty level
o Modify the class diagram to include these methods above
o In the main program, call each of the methods above to display the results on the screen.
Q2] Study the class diagrams below and answer the questions which follows.
Vehicle
VehicleMake : String //initialise to “N/A”
VehiclePrice : Integer //initialise to -1
Constructor() //initialise all the attributes
ShowMake() //display make of vehicle
ShowPrice () //display price of vehicle
SetMake() //prompt user to enter a make for the Vehicle
SetPrice () // prompt the user to enter a price for the Vehicle
The bae class is Vehicle and the child class is Car.
Car
CarNumDoors : Integer //initialise by a parameter
Constructor() //initialise all the parameters
ShowNumDoor() //display number of doors

(a) Write program code for both classes


(b) In the main program, prompt the user to enter a value for Number of doors of the car
(c) Create an object for the SuperClass Vehicle using the identifier, NewVehicle.
(d) Create an object for the class Car using the identifier NewCar
(e) Use the methods in the class diagrams to display the results.

You might also like