End of Chapter

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

  public int compareTo( Monster other )
  {
    int hitDifference = getHitPoints()-other.getHitPoints();
    
    if ( hitDifference != 0 )
      return hitDifference;     
    else
      return getStrength()-other.getStrength();
      
  }

End of Chapter

For a tiny (and somewhat silly) game that uses the Monster class, see the exercises.

You have reached the end of the chapter. You may wish to extend your knowledge by examining the following.

You have reached the end of the chapter.

go to previous page   go to home page