Lab 7

Purpose

In these lab assignments you will continue to work with data structures. However, these labs focus on dynamic structures (i.e. ArrayList and linked lists) as opposed to static structures (such as arrays). While arrays offer many advantages, as you learned from the last lab, adding and removing elements to and from an array can be complicated. Further, when the number of elements to be stored is not known in advance, a data structure that can adjust as elements are added (a dynamic structure) is a better option. It is important to understand the difference between dynamic and static structures, including when to use each.

Key Reading

  • Lab 7 (In suggested order)
    • 4.8 (Follow the structure of a driver and separate panel class used here)
    • 3.9, 3.11
    • 4.9
    • 5.10
    • 7.7
  • Lab 8
    • 12.1 - 12.3

Introduction

IMPORTANT NOTE!

Labs 7 and 8 are two labs that combine to produce one program. As a whole, the project is rather lengthy and that is why it consists of two related labs. Each part of this project builds upon previous parts and requires the previous parts to be functioning. Because labs 7 and 8 are both part of the same program, we have combined them into one web page.

The Colosseum

Well, after inventing time travel, you go back to visit the Romans and check out the Colosseum. With the wealth of experience you have gained in CS 142 so far, you set out to write some software that will help run the Colosseum better.

You will need to create a GUI that will allow you to manage the gladiators, which involves adding new gladiators, viewing information about any given gladiator, and arranging battles between pairs of gladiators. You must also be able to simulate the battle after which the losing gladiator is removed from the Colosseum to live out the rest of his life in shame.

Requirements

Initial Notes

  • You must use two different data structures for this lab. Both structures must be dynamic (no arrays) - one must be a pre-defined Java class (e.g. ArrayList) and one must be a data structure of your own creation (e.g. not a pre-defined class such as LinkedList). The data structure you implement must be a linked data structure that does not use arrays.

Lab 7 Part 1 - Build the Colosseum (10 points)

  • Create a Java GUI that has appropriate components to do all of the following:
    • Accept the name and skill level of a new gladiator and add him to the list of gladiators.
    • Display the total number of gladiators in the Colosseum.
    • Accept the index of a gladiator in the list and display his name, skill level, number of victories, and current opponent.
    • Set up a match between two gladiators given their indices in the list and display whether the match could be created (see lab 8 part one for match creation).
    • Remove the last gladiator in the queue (“Run!” button in example GUI)
    • Simulate a battle between two previously matched gladiators.
    • Display the number of gladiators waiting for battle
    • Display the names of the gladiators who will compete in the next battle.
    • Display the names of the winner and loser of the most recent battle.
  • Complete part 1 fully before you start on part 2.
  • Part 1 is merely the GUI setup. Your GUI need only appear with the necessary buttons, labels, text fields, etc. The user does not need to be able to interact with the GUI and no use of data structures is necessary. Functionality will be added in the other parts of the lab.

Lab 7 Part 2 - Gladiator Check-In (15 points)

  • Create a class to represent a gladiator. You may design this class as you wish, with one requirement: this class must have a way of storing the opponent of a gladiator.
  • Initialize the Colosseum to start with 5 gladiators. These may be hard coded or you can randomly create names and skill levels; whichever you as the programmer prefer.
  • Add functionality to allow the user to add new gladiators. The user will specify the name and skill value of the gladiator.
  • The display for the number of gladiators in the Colosseum must be correct at all times.

Lab 7 Part 3 - Checking Out the Competition (5 points)

  • Add functionality to allow user to view any gladiator currently in the Colosseum. The user should enter a number for the index of the gladiator (e.g. the user types in 7 to see gladiator number 7 in the list).
  • The selected gladiator's name, skill level, number of victories, and opponent, if one exists, should be displayed.
  • See Range Checking in Lab 8.
Designed by Andy Griffin