0% found this document useful (0 votes)
12 views

Tutorial 7

The document describes three exercises: 1) Creating a SportsVenuePass class with private instance variables used and passId, 2) Creating a TaxiCar class and CarsDatabase class to manage TaxiCar objects, storing them in an ArrayList, 3) A main program class to test the CarsDatabase class by creating TaxiCar objects, adding some to the database, and testing the CarsDatabase methods.

Uploaded by

mariyamma sadaf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Tutorial 7

The document describes three exercises: 1) Creating a SportsVenuePass class with private instance variables used and passId, 2) Creating a TaxiCar class and CarsDatabase class to manage TaxiCar objects, storing them in an ArrayList, 3) A main program class to test the CarsDatabase class by creating TaxiCar objects, adding some to the database, and testing the CarsDatabase methods.

Uploaded by

mariyamma sadaf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Exercis e 1: Static attributes . Write the code for a clas s nam ed Sports VenuePas s .

This clas s will


be us ed to ins tantiate objects that repres ent the right to acces s a perform ance in the s ports
venue. The clas s will have 2 private ins tance varia bles : a boolean va riable nam ed us ed and an
integer variable nam ed pas s Id. The boolean variable us ed will be initialis ed to fals e and cha nged
to true by the m ethod : us eThis Pas s which will be ca lled when the pas s is pres ented at the s ports
ground. When the pas s is created, a unique new id num ber is allocated to pas s Id. This id num ber
will be generated by a dding one to the previous ly us ed pas s Id num ber, which is kept s tored in a
varia ble s hared by all Sports VenuePas s objects .

Exercis e 2: Data Management Clas s

a) Write a clas s to repres ent a car us ed as a taxi. The attributes are: the m ake/ m anufacturer, the
m odel, the regis tration licence plate, total kilom etres driven, and a flag indicating whether it is
currently being driven out on the s treets . Include appropriate cons tructors , acces s ors , a mutator to
change the flag, and a m ethod to increas e the num ber of kilom etres driven.

b) Write a clas s , nam ed Cars Databas e, which will be us ed to provide the res pons ibility of data
m anagem ent of a s et of TaxiCar objects . Internally, it s hould us e an ArrayLis t of TaxiCar. It s hould
provide:

1. a m echanis m to add a new car into the Cars Databas e clas s ,


2. a way to report the total num ber of cars that are being m anaged,
3. a s afe way to obtain a n ArrayLis t of all the ca rs that are being m ana ged,
4. a s afe way to obtain a n ArrayLis t of all the ca rs that are currently out on the s treets

c) Write a m ain-program clas s which:

1. Creates an ins tance of the Cars Databas e.


2. Creates s everal different cars and adds thes e to the Cars Databas e. Before adding them ,
m odify a few to m ake them s eem to be ‘in-us e’, and s et the dis tances travelled for s om e of
them to be higher than the default dis tance of 0.
3. Tes t that each of the m ethods of the Cars Databas e clas s is working correctly

You might also like