Java Player Class Primer Tutorial

Java Player Class Primer Tutorial

Java Player Class Primer Tutorial

An important part of the OOP design phase, here, today, using Java, is your imagination of which classes should exist, and then what their interaction should be.

Sometimes you want to work on one class to completion and hope it satisfies what is required of it later, and this can suit the work arrangements for one programmer in a team of programmers. As that programmer, you may want to add a main() function to that class to simulate an interaction with another class to see how your class functions, as an independent compilable and runnable Java program. So, today, we write a Player class and include within it a main() function that simulates what a Game class may ask of it.

You often find it useful in Java to define a Class toString override method (via the @Override syntax), and we use one of these with today’s Java code.

How do you arrange the unit testing environment of a Player class playing a Game without that Game class existing? Today, we do it by accepting Player names on the command line and have them play each other with the code deciding randomly who out of those two Player objects won the Game. Of course this favours the earlier Player objects because the opponent of subsequent Player objects can be any one of the previous Player objects, but, guess what? The results of our run of our tutorial, at least, don’t favour the favourite!

So please see some downloadable Java programming source code you could call Player.java

If this was interesting you may be interested in this too.

This entry was posted in eLearning, OOP, Tutorials and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>