Forums Register Login

Looking For Feedback On My Program

+Pie Number of slices to send: Send
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):

+Pie Number of slices to send: Send
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.
Create symphonies in seed and soil. For this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 859 times.
Similar Threads
local variable initialisation
having problem with ninja fighter class
generate random number into 2d arrays
Question About Inheritance
Conceptual Misunderstanding of Arraylists?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:07:13.