« All Events
5 PM – Intro To Java – Gamas
April 30, 2022 @ 5:00 pm - 6:00 pm
Today We Do
- We added Dragon.java class and made it inherits from Monster.java
- Using inheritance, we overrode Monster.doDamage(int damage) inside Dragon class.
Homework
- Create Troll.java class and made it inherits from Monster.java. Use this Troll class inside MonsterInheritanceMain.initializeMonster() method.
- Using inheritance, we overrode Monster.doDamage(int damage) inside Troll class so it will make Troll immune to melee attack. Inside this method, make sure to print “Troll is immune to hand to hand attack. No damage is done.”. This is very similar
- Inside MonsterInheritanceMain when user select “1. Magic attack”, display the following menu
What do you want to do with the dragon:
1. Magic attack
2. Melee attack
3. Arrow attack
4. Heal
Enter your selection:1
What kind of magic attack you want to do to dragon:
1. Fire magic - 10 damage
2. Water magic - 10 damage
3. Earth magic - 12 damage
4. Wind magic - 8 damage
Enter your selection:1
You attacked dragon with fire magic and did 10 damage to DRAGON.
DRAGON attacked Gamas and did 10 damage