You are on page 1of 2

1

CSC238 - LAB EXERCISE (POLYMORPHISM)

The Department of Computer Science, Thistle University has organized an ICT Festival recently.
The festival accepts contributions of ideas or ICT products from exhibitors and contestants. The
exhibitors may come from government or private sector. Meanwhile, contestants have two
categories of ages which are junior or senior.

Given the following superclass and subclasses:

public abstract class ICTFestivalParticipant


{
protected String participantName;
protected int participantID;
protected String email;

//normal constructor
//setter methods
//getter methods

public abstract double enrollCharge();


//toString method
}

public class Exhibitor extends ICTFestivalParticipant


{
private char sector; //G for government, P for private

//normal constructor
//setter methods
//getter methods
//toString method
}

public class Contestant extends ICTFestivalParticipant


{
private int level; //1 for junior, 2 for senior

//normal constructor
//setter methods
//getter methods
//toString method
}

The enrollment charge is based on the table below:

Participation Enrollment Charge (RM)


As Exhibitor
Government Sector 250.00
Private Sector 300.00
As Contestant
Junior 120.00
Senior 150.00

Edited and Prepared by Puan Yusnita Sokman


2
CSC238 - LAB EXERCISE (POLYMORPHISM)

Use the concept of polymorphism to perform the following tasks:

a) Complete the class definitions above.

b) Write an application class that will do the following:

• Declare an array named participant of class ICTFestivalParticipant to store


information of all exhibitors and contestants.
• Read all data and store it into the array.
• Calculate and display the total charge received from the private sector.
• Count and display the number of junior contestants.
• List the id and names of exhibitor(s) for those who have participated in ICT festival from
the government sector.

Edited and Prepared by Puan Yusnita Sokman

You might also like