Objectives

The goal of this lab is to learn the following concepts:

Overview

In this lab, you will learn how to use blueprints in classes. Blueprints are descriptions of what kind of functionality a class will provide. The idea behind blueprints is to specify the structure of a class without providing an implementation. Using inheritance, you can then use the blueprints to make similar classes use the same actions with the same names to do similar things. In this lab, you are going to create a SuperHero class to create superhero characters. Then, you will use a blueprint action to build each character's inventory and powers. Since the inventory and powers of superheros are different from other superheros, a blueprint action makes good sense to use.

Task 1: Getting Started

Start Sodbeans. Create a new “Quorum Application” project, and name it Lab6_2. In the Main.quorum file, it should contain a Main class and Main action.

Create six additional classes in this project. Name the classes SuperHero, Equipment, SuperPower, Spiderman, Superman, and CaptainAmerica.

Task 2: Building Characters

You are going implement two helper classes that will help set and get the names of equipment and superpowers for the heroes. Both classes should have the following:

In class SuperHero, you can use the helper classes above to create arrays that will hold the names of equipment and powers for our heroes. The arrays can be created like so:

Array inventory
Array powers

The arrays above are of type Equipment and SuperPower. That is, they will be made of they types that are present in those classes, instead of just type integer or type number. In this case, the arrays will be holding text values. Remember that you must use Libraries.Containers.Array to access the array class. Next, create the following actions:

Task 3: Inheriting blueprint actions from another class

In this task you will be implementing the inherited blueprint action BuildCharacter for classes Superman, Spiderman, and CaptainAmerica. The BuildCharacter action should do the same thing for each class: add equipment and powers to the hero using the setters from classes Equipment and SuperPower, and add the values to the proper array using the AddEquipment action from class SuperHero. For each superhero (Superman, Spiderman, and Captain America), add powers and pieces of equipment that describe that particular hero. i.e:

//Superman
action BuildCharacter
    Equipment cape
    cape:SetEquipment("has a cape")
    parent:SuperHero:AddEquipment(cape)

    SuperPower vision
    vision:SetPower("can use laser vision")
    parent:SuperHero:AddSuperPower(vision)
end

In the above example, I described that Superman has a cape and can use laser vision. For each superhero, create a combination of at least 5 powers and/or equipment that that superhero has.

Task 4: Using inherited actions

After you have action BuildCharacter implemented for each superhero, go into Main and instantiate an object of each superhero and call BuildCharacter. Then, using the SaySuperPowers and SayInventory actions, list the powers and inventory of each superhero for the user. Notice the BuildCharacter action that is called is unique to each superhero.

Sample Output

When run, the user should be told which superhero is being described, and then told that superhero's powers and equipment. Here is a sample output for Superman:

Superman
has a cape
has a blue costume
can use laser vision
can use super strength
can fly

When finished, debug and fix any errors, then show your instructor you code.

Next Tutorial

In the next tutorial, we will discuss Lab 6.3, which describes another practice session with inheritance.