Objects III

Today we finish our practice with objects. Objects are an important concept in many programming languages, and particularly in Java. Today’s focus is on several new intermediate object-oriented programming concepts: inheritance, typecasting, and function overriding.

We will also discuss the overall Java class system. The programming component allows you to utilize the power of inheritance to expand the functionality of the Pokémon program that you started in Lab 4.

1. Written Exercises (45 Minutes)

As usual, we begin with a written lab component. Please complete these exercises carefully. Your course staff will review and discuss your answers along with the rest of your section.

Complete this part of the lab in pairs using Google Docs. Create a copy of our document template, and then edit it to record you and your partner’s answers. Note that you must open this document using your @illinois.edu Google Apps account. We will not grant access to non-Illinois users.

Have a course staff member check your answers as you go. When you are done, move on to the programming component.


2. More Pokémon Objects (60 Minutes)

Like any other programming concept, the way to get familiar with objects is to use them. In the second half of the lab we’ll provide you with some practice at utilizing the relationships between objects.

And we’ll try to make it as interesting as possible by having you continue working with the Pokémon objects that we introduced in Lab 4.

2.1. Forking and Cloning the Lab6 IntelliJ Project

We’ve set up an Lab 6 GitHub repository containing an IntelliJ Project that’s correctly configured for Lab 6. Getting access to it is similar to how you imported MP0. But you have to fork our repository first. If it’s not obvious how to do that, try following these instructions.

2.2. Your Goal

We’ll continue where we left off last time. Except this time you have the chance to implement several new types of Pokémon: Electric, Fire, and Water Pokémon.

Start by examining the base Pokémon class in Pokemon.java. This type of Pokémon will perform a normal attack. However, when fighting the specialty Pokémon they will have a chance to do their special attack under certain conditions: if they are not already defeated, and if the roll of the dice goes their way.

You’ll need to complete the implementation of the specialty attack methods for the Electric, Fire, and Water Pokémon. You’ll also need to rewrite the buildPokemon method to build specialty Pokémon correctly depending on the user input. Once that’s done, your specialty Pokémon will be ready to battle in the Colosseum!

3. Help with MP4 (20 Minutes)

Use any remaining time in your lab section to get help with MP4.

CS 125 is now CS 124

This site is no longer maintained, may contain incorrect information, and may not function properly.


Created 10/24/2021
Updated 10/24/2021
Commit a44ff35 // History // View
Built 10/24/2021 @ 21:29 EDT