Hero Stats Editor

Putting variables, user input, and arithmetic into practice within a gaming context.

Task 1: The Character Drawer

Setting up your first Hero class

01
New ClassCreate a class named 'HeroStats'
02
SkeletonPrepare the public static void main method
03
DeclareCreate hp (int), crit (double), and isAlive (boolean)
HeroStats.java
java

Task 2: Stat Editor

Mastering User Input with Scanner

01
Import Import Scanner library.
02
Object New Scanner object.
03
Read Read and output integer.
HeroStats.java
java

Task 3: The Immortal Guard

Protecting critical stats with 'final'

Lab Mission

Define MAX_HP and try to modify it later.
HeroStats.java
java

Task 4: The Division Duel

Run the code to discover the difference!

DivisionTest.java
java

Stop & Think

The Type Trap

01

The Trap

What if you run nextInt() but input 12.5? Does it round or just crash?
02

The Fix

Change your code to use nextDouble(). Can it handle decimal input correctly now? Give it a shot!

Bonus Challenge

The Loot Master Mission

A dragon's chest has been found! Create a Java program that calculates how to split the gold.

  • 1. Initialize final int CHEST = 100;.
  • 2. Get the number of players (int players) from the console.
  • 3. Determine the share each player gets (int share).
  • 4. Factor in a double luckBonus from the user.
  • 5. Print the total gold each player receives.