← Back to Home

Sprint Challenge

Challenge Overview

In this sprint challenge, you will demonstrate your understanding of loops, arrays, the UPER framework, and pass-by-value concepts by implementing a data processing system.

You will be using the same repository from Sprints 1 and 2, and should be completing Mastery Tasks 7, 8, and 9 as part of this challenge.

Learning Objectives Assessed

Loops

  • Implement repetitive execution of a code block using while and for statements
  • Implement nested looping statements for complex iterations
  • Use break and continue statements to control loop flow
  • Predict the resulting values of variables modified by several iterations

Arrays

  • Use arrays to store collections of the same data type
  • Access and modify elements in one-dimensional arrays
  • Work with array initialization and default values
  • Use for-each loops to iterate through array elements

UPER Problem-Solving Framework

  • Apply the UPER framework to systematically solve coding problems
  • Break down complex problems into manageable components
  • Develop effective plans before implementing solutions
  • Reflect on and optimize implemented solutions

Pass-by-value

  • Understand how Java passes primitives and reference types to methods
  • Predict the effects of method parameter modifications
  • Distinguish between modifying object state and reassigning references

Mastery Task 7 - Loops and File Reader

Task Overview

In this task, you will implement an automated combat system using loops and a file reader to demonstrate your understanding of loops in Java.

App Update

Inside of com.adventure.settings.AppSettings, update the story MT7_MonsterScene.

Working Classes

You will be working with the following classes:

  • Monster (already built) - adventure.world.Monster
  • CombatController - adventure.CombatController
  • Player - adventure.player.Player
  • SceneDescriptionFileReader - adventure.scenes.SceneDescriptionFileReader

Combat System

When a Player encounters a Monster, the game will build a CombatController that will pit the player and the monster into a battle.

Each fighter takes a turn hitting the other and the one that gets the other fighter to 0 health first, wins.

The amount of health points that are taken away is based on the fighter's power. So if the player has 10 health and the monster has a power of 2, then when the monster hits the player, the player's health goes down by 2 points and the player now has 8.

See the CombatController file for more information on how to properly implement its behavior.

Hint: only one loop should be necessary to complete this task.

Player

You will need to update Player.setWeapon(). See the function's comments to see how it should work.

File Reader

Reading files is perhaps the most common use case for while loops. That's because when you read in a file, you don't actually know how long the file is. For loops are used when we know how many iterations are required, so using a for loop here would not work.

This Sprint introduces the capability of scenes to have their descriptions inside of text files as opposed to being hardcoded in classes.

Read the class SceneDescriptionFileReader to learn about BufferedReader which is a class commonly used to read in files. It will tell you the essential characteristics of BufferedReader and how to successfully use it to read in a text file's contents.

For Windows Users: To avoid unnecessary errors, make sure the path to your project does not contain spaces.

Bad path: /my project/bd-java-fundamentals-1...
Good path: /MyProject/bd-java-fundamentals-1...

Testing

To run the tests for this assignment, run the following:

./gradlew test --tests com.adventure.MT7

or by right-clicking the MT7 file and selecting "Run 'MT7'"

You can check your code styling by running the linter with the following command:

./gradlew checkstyleMain

You can run the game by going to the Main class and clicking on the run icon to the left of the main() method.

Mastery Task 8 - Arrays

Task Overview

In this task, you will implement an array-based inventory system to demonstrate your understanding of arrays and loops in Java.

Arrays

We are going to change how the player object stores items like keys and shovels. Instead of storing them in separate objects, we're going to store them in an array. This will require us to loop through the array to perform various actions.

Backpack

Open the Backpack class and read the comments.

Fill in the TODOs to complete the object.

Player

In the Player object, do the following:

  • Remove the Key and Shovel objects and replace them with a Backpack object with scope of private. This will cause some issues with the setters and getters.
  • Rewrite the logic for the setters and getters so they store/retrieve the items using the backpack. For the getters, use a default String to get the object. ("key" for getKey, "shovel" for getShovel).
  • Update the method addItem that takes an item of type Tangible. This method will then pass the item onto the backpack's addItem call.
  • Update the method getItem that takes a String name and returns an object of type Tangible. It will pass this along to the backback's getItem method.
  • Update the method removeItem that takes a Tangible item. This will pass the item onto the backpack's removeItem method.
  • Create the method printItems that calls the backpack's printItems method.
  • You may need to update some functions such as setShovel, setKey, etc, so they become convenient functions that simply call addItem.

GameController

With the backpack now complete, we need to include logic for the CommandVerb INVENTORY (you may need to update CommandVerb to account for the INVENTORY enum if it's not already handled).

In GameController find the method applyCommand. Add INVENTORY to the switch statement's cases and have it call player.printItems.

Testing

To run the tests for this assignment, run the following:

./gradlew test --tests com.adventure.MT8

or by right-clicking the MT8 file and selecting "Run 'MT8'"

You can check your code styling by running the linter with the following command:

./gradlew checkstyleMain

You can run the game by going to the Main class and clicking on the run icon to the left of the main() method.

Mastery Task 9 - OmniDoor and OmniKey

Task Overview

In this task, you will implement OmniDoor and OmniKey objects using the UPER problem-solving framework.

OmniDoor and OmniKey

In this Mastery Task, we're going to introduce two new objects: OmniKey and OmniDoor. You will want to read the documentation in each of their files carefully and use UPER to come up with the correct solution. Open each of their files and fill in the TODOs to complete the objects.

Testing

To run the tests for this assignment, run the following:

./gradlew test --tests com.adventure.MT9

or by right-clicking the MT9 file and selecting "Run 'MT9'"

You can check your code styling by running the linter with the following command:

./gradlew checkstyleMain

You can run the game by going to the Main class and clicking on the run icon to the left of the main() method.