• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Looking For Feedback On My Program

 
Ranch Hand
Posts: 31
Android Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy!
I'm looking for feedback on my simple fighting program. It runs just fine and I don't see any bugs, so I'm looking for feedback on what I could've done to make it less verbose, more readable, and just generally want to hear any advice you guys have to improve.
I have a feeling that there is a much easier way to implement a structure that avoids displaying a negative health value rather than all those if/else statements...

I will post all of the classes in their entirety:

FightTest.java:


Boxer.java:


Ninja.java


Some sample output(with many of the rounds cut out so you guys don't kill me :S):

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code is good. Three things I can think of to improve:

1) Change "else if(ninjaHealth <=0 && boxerHealth <= 0)" to "else" and remove the else that says the code shouldn't get there. The if/else blocks are mutually exclusive so you can just end with an else and make the extra one impossible.

2) Add a helper method the outputs the boxer health, ninja health and a message so there isn't code all over that looks like:

Instead you would have:

This makes the main logic easier to read and removes some repetition.

3) The Boxer and Ninja classes are the same except for the value. You could have a generic Fighter class that takes this value as a constructor. Or create subclasses of that generic Fighter class to supply that value.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic