You are on page 1of 6

B

Lab Test 1: Object, Class and ArrayList

This lab test is divided into FIVE stages Stage 1, Stage 2, Stage 3, Stage 4 and Stage 5.

You need to complete prior stages without errors before you can proceed to the respective next
stages.

To do this lab test you are provided with five files Tester1.java, Tester2.java,
Tester3.java, Tester4.java and Tester5.java.

Before you start, you need to do the following:

1. Create a folder on Desktop and name the folder using your matric number.
2. Open eclipse and set the folder named using your matric number as your workspace.
Problem Background
There is a rumor circulating on the internet that George Lucas (the creator of the Star Wars movies)
uses a formula to create the names for the characters in his stories (Jar Jar Binks, ObiWan Kenobi,
etc.). The formula allegedly is this:

Your Star Wars first name:


1: Take the first three letters of your last name.
2: Add to that the first three letters of your first name.

Your Star Wars last name:


1: Take the first three letters of your mother's maiden name.
2: Add to this the first three letters of the name of the town or city you were born in.

Your clan:
Given the Clan array {"Bear", "Boma", "Clawmouse", "Dragon", "Hawkbat", "Heliost", "Katarn",
"Wolf", "Savrip", "Squall", "Thranta"}. Your clan will take the ith position which is determined by
the size of your birthplace String. If it has the same size or is larger than the size of the Clan array, i
becomes the size of birthplace/2.

Stage 1
You have been asked to develop a program to manage a list of Star Wars Fan Club members.
Therefore, the first thing that you need to do is to define a class to create an object of a Star Wars Fan
Club member:
1. Create a Java project named LabTest1-B-Stage1.

2. Copy class Tester1.java into your project.

3. Define a class named Member. The class should have:

i. Instance variables to hold the first name, last name, mothers maiden name, place of birth, Star
Wars first name, Star Wars last name and Star Wars clan name of a member.

ii. A suitable constructor to assigns the value of the instance variables in 3(i).

iii. Suitable methods to access the instance variables in 3(i) from outside of the class.
4. Check your answer by invoking the main method in class Tester1, and your output should be
as follows:
Member details
--------------
First name: Wannabe
Last name: Obirus
Mother's maiden name: Keneddy
Place of birth: Obidos
Star Wars first name: null
Star Wars last name: null
Star Wars clan: null

Stage 2
Next, you need to define a class to create an object to manage the Star Wars Fan Clubs list of
members:
1. Create a Java project named LabTest1-B-Stage2.

2. Copy class Tester2.java and Member.java (from stage 1) into your project.

3. Define a class named StarWarsFanClubRegister. The class should have:

i. An instance variable to hold the list of club members.


ii. A suitable constructor to create the list in 3(i).
iii. A suitable method to access the list of club members from outside of the class.

4. Check your answer by invoking the main method in class Tester2, and your output should be
as follows:

Total of Star Wars Fan Club members: 0


Stage 3

The program needs a feature to add a new member into the clubs list of members. Therefore, you
need to:
1. Create a Java project named LabTest1-B-Stage3.

2. Copy class Tester3.java, as well as Member.java and


StarWarsFanClubRegister.java (from stage 2) into your project.

3. Add into class StarWarsFanClubRegister a suitable method to implement the mentioned


feature.

*Take note that the method must return true if the addition of a new member is successful, or
return false if otherwise.
4. Check your answer by invoking the main method in class Tester3, and your output should be
as follows:
Addition of new member Wannabe Obirus has been succesfully executed
Addition of new member Muneerah Azlan has been succesfully executed
Addition of new member Wannabe Obirus has failed because person has been
added before

Total of Star Wars Fan Club members: 2

Stage 4
The second feature that program needs is a feature to generate the Star Wars first name and last name
for a member of the club. To implement this feature, you need to:
1. Create a Java project named LabTest1-B-Stage4.

2. Copy class Tester4.java, as well as Member.java and


StarWarsFanClubRegister.java (from stage 3) into your project.

3. Add into class Member the suitable methods (setter) to assign a members Star Wars first name
and last name.
4. Add into class StarWarsFanClubRegister a suitable method to generate and assign a
members Star Wars first name and last name, based on the alleged formula that George Lucas used.
*Take note that you need to use one of following methods in the String class to implement this
method.

5. Check your answer by invoking the main method in class Tester4, and your output should be
as follows:
Addition of new member Wannabe Obirus has been succesfully executed
Addition of new member Muneerah Azlan has been succesfully executed
Addition of new member Wannabe Obirus has failed because person has
been added before
Addition of new member Julia Roberts has been succesfully executed

Total of Star Wars Fan Club members: 3

My boring name is Wannabe Obirus


I was born in Obidos
My Star Wars name is ObiWan KenObi

My boring name is Muneerah Azlan


I was born in PortDickson
My Star Wars name is AzlMun NorPor

My boring name is Julia Roberts


I was born in LostAngeles
My Star Wars name is RobJul AmaLos
Stage 5

The final feature that program needs is a feature to generate the Star Wars clan for a member of the
club. To implement this feature, you need to:
1. Create a Java project named LabTest1-B-Stage5.

2. Copy class Tester5.java, as well as Member.java and


StarWarsFanClubRegister.java (from stage 4) into your project.

3. Add into class Member a suitable method to assign a members Star Wars clan.

4. Add into class StarWarsFanClubRegister a suitable method to generate and assign a


members Star Wars clan, based on the alleged formula that George Lucas used.

5. Check your answer by invoking the main method in class Tester5, and your output should be
as follows:

Addition of new member Wannabe Obirus has been succesfully executed


Addition of new member Muneerah Azlan has been succesfully executed
Addition of new member Wannabe Obirus has failed because person has
been added before
Addition of new member Julia Roberts has been succesfully executed

Total of Star Wars Fan Club members: 3

My boring name is Wannabe Obirus


I was born in Obidos
My Star Wars name is ObiWan KenObi
I am from Katarn clan

My boring name is Muneerah Azlan


I was born in PortDickson
My Star Wars name is AzlMun NorPor
I am from Heliost clan

My boring name is Julia Roberts


I was born in LosAngeles
My Star Wars name is RobJul AmaLos
I am from Thranta clan

SELAMAT MAJU JAYA

You might also like