Java
TOPIC 37 – CONSTRUCTORS II
LESSON WORK
QUESTION #1 – SHORT ANSWER
QUESTIONS
Do the Short Answer
Questions – Constructors (Part 2) from Java OOP Exercises I.
QUESTION #2 – OUR OWN BADGUY CLASS
a) We will create a Badguy class. We will decide as a group on 4 or 5
different attributes (data fields) that we want our Badguys
to have.
Possibilities include: name, hp, attack, defense,
accuracy, speed, …
b) Add a constructor that gets a value for each data field.
c) Add a constructor that gets strictly a name as parameter and then creates
that pre-defined Badguy. For example, if the name is
"Bowser", it will give the predetermined stats for Bowser. If the name is "Mushroom", it
will give other predertermined values to the data
fields. Include at least 4 different
predetermined Badguys.
d) Add a constructor that gets a single int called level as parameter. The value of level will range from 1 to 4
with 4 being a very strong bad guy. It then creates a random Badguy based on the level provided. For the name, it probably makes sense to
create a method that generates a random name for us.
e) Add a
constructor that has no parameters. It
will create a random badguy. There is a 50 percent chance that the badguy is level 1, 30 percent chance that it is level 2
and a 20 percent chance that it is level 3.
Note that you can call the previous constructor here.
f) Test the above class. Make sure you
test each constructor.
QUESTION
#3 – CIRCLE CLASS
Do the Circle class 2 work from Java OOP Exercises I.
|