{"id":7765,"date":"2014-05-23T05:04:23","date_gmt":"2014-05-22T19:04:23","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7765"},"modified":"2016-03-28T12:24:17","modified_gmt":"2016-03-28T02:24:17","slug":"java-player-class-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/java-player-class-primer-tutorial\/","title":{"rendered":"Java Player Class Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Player\/Player.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Java Player Class Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Java\/Player\/Player.jpg\" title=\"Java Player Class Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Java Player Class Primer Tutorial<\/p><\/div>\n<p>An important part of the <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Object-oriented_programming' title='Object Oriented Programming information from Wikipedia ... thanks'>OOP<\/a> design phase, here, today, using Java, is your imagination of which classes should exist, and then what their interaction should be.<\/p>\n<p>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.<\/p>\n<p>You often find it useful in Java to define a Class <a target=_blank href='http:\/\/www.tutorialspoint.com\/java\/number_tostring.htm' title='toString override method in Java'>toString<\/a> override method (via the <i>@Override<\/i> syntax), and we use one of these with today&#8217;s Java code.<\/p>\n<p>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 <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Player\/Player.jpg\" title='Click picture'>tutorial<\/a>, at least, don&#8217;t favour the favourite!<\/p>\n<p>So please see some downloadable Java programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Java\/Player\/Player.java_GETME\" title='Player.java'>Player.java<\/a><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d7765' onclick='var dv=document.getElementById(\"d7765\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Java\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7765' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/java-player-class-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,28,37],"tags":[210,644,849,875,1837,1836,997,1319],"class_list":["post-7765","post","type-post","status-publish","format-standard","hentry","category-elearning","category-oop","category-tutorials","tag-class","tag-java","tag-object","tag-oop","tag-overload","tag-override","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7765"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=7765"}],"version-history":[{"count":1,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7765\/revisions"}],"predecessor-version":[{"id":20912,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7765\/revisions\/20912"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=7765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=7765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=7765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}