aspose file tools*
The moose likes Beginning Java and the fly likes Looking For Feedback On My Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Looking For Feedback On My Program" Watch "Looking For Feedback On My Program" New topic
Author

Looking For Feedback On My Program

Justin Coombs
Greenhorn

Joined: Oct 10, 2012
Posts: 22

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):



Nothing is withheld from us what we have conceived to do.
-Russel Kirsch-
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looking For Feedback On My Program