Java VII
Home Up Java I Java II Java III Java IV Java V Java VI Java VII Code

 

In this lesson, the Color Belot application is completed by adding a top level class along with a main program.  Recall that lesson 1 explained the mechanics of a very simple application.  To write an application, there must be exactly one "public" class and that class must contain a main method.  The code for today's lesson is located in the file "Belot.java".

In the code below, the name of the "public class" is "Belot" and the program that is executed when the application is run is prefixed by the header "public static void main (String [] args)".  Would you like to review the meaning of either static or public?

The body of the main program works as follows.  First a new "Game" object is created called "belotGame".   The "dealFiveCards" method is invoked to deal five cards to each player and then the player's hands are printed through the "printStatus" method.   Trump is called via the "callTrump" method and then each player receives his final three cards via the "finishDealing" method.  Once again the player's hands are printed using the "printStatus" method.  Special Color Belot scoring bonuses such as runs are scored via the "scoreBonuses" method and then a game of Color Belot, consisting of eight tricks, is simulated via the "playCards" method.  Finally, the game score for each player is calculated via the "calculateScores" method and then these scores are printed via the "printStatus" method.

Notice that in this tutorial, a bottom-up approach has been taken.  First the lowest level class (BelotConstants) was introduced and then classes that built upon previously described classes were presented.  When the application was actually constructed, a mixture of bottom-up and top-down strategies was used to develop the final code.  For the tutorial, it is convenient to present the classes using a bottom-up approach.   However, when crafting a solution, the reader should use whatever design technique is effective for him or her.