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

Assignment 2 2016 Nov

Uploaded by

lakmal bandara
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)
9 views2 pages

Assignment 2 2016 Nov

Uploaded by

lakmal bandara
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
You are on page 1/ 2

Bachelor of Information Technology (External Degree)

Level 1 Semester 1
ITE 1101 - Fundamentals of Programming

Assignment 02

1. Create a class called Bicycle which has four integer member variables called gear,
cadence, speed and ID and one class variable called noOfBicycles to count the how many
bicycle objects created.

Define a constructor to bicycle class, which has three arguments to initialize the gear,
cadence, speed of the bicycle object when it is created. Inside the constructor you must
initialize the ID by using following statement;

ID = ++ noOfBicycles;

Define a new member function getID() to return the id of the bicycle and define a class
method getNumberOfBicycles() to returns the no of bicycle object.

Create a new class called MountainBike which derived from Bicycle class and it has an
own member variable called seatHeight to store the height of the seat.

Define a constructor to MountainBike class, which has four arguments (to initialize the
gear, cadence, speed and seatheight).
Hint: inside the constructor, call the suitable constructor of the super class by
passing the suitable variables to it and initialize the seatHeight instance variable.

Define a member function called getSeatHeight() to output the seat height of the
MountainBike object.

Create another class called BicycleClass which have a main method and create two
mountain bike objects b1 and b2 using MountainBike constructor. Then display the bike
IDs as follows.

System.out.println("Mountain Bike 1 ID="+b1.getID());


System.out.println("Mountain Bike 2 ID="+b2.getID());

Then display the No of bicycles by calling the proper method.

2. Create a new class called TandemBike which derived from Bicycle class and it has an
own member variable called noOfHeaders to store number of handles it has.

Define a constructor to TandemBike class, which has four arguments (to initialize the
gear, cadence, speed and noOfHeaders).
Hint: inside the constructor, call the suitable constructor of the super class by
passing the suitable variables to it and initialize the noOfHeaders.

Define a member function called getNoOfHeaders() to output the number of headers.


Then modify the above BicycleClass class (in question no 1) as follows. Create a tandem
bike object called b3 and display it’s ID. Then display the No of bicycles by calling the
proper method.

3. Modify MountainBike and TandemBike classes to count the how many bicycle objects
from each type separately.

Compress all these files under your registration number and upload it to LMS.

You might also like