CS 280 Spring 2009           Assignment 9 – Multiple Classes Working Together                                100 “Assignment” points

 

Assigned: 04/02/2009

Due: 04/16/2009 at the start of class  (after break)

 

Pre-Lab (Do Before Lab):  Bring materials – a USB for a take home copy.

 

Main Assignment:

You are writing some parts of a game scoring (simplified demo) program. We are still quite a ways away from being able to do the whole job, so please pay attention to what I’m asking for. Your job is to 1) Write a Score class as described below (and in Javadoc documentation); 2) Add to the Player class as described below (and in Javadoc documentation);  3) Write a GUI that demonstrates some of the capabilities as described below. You will be updating my provided Player class, and will also be using (a tiny bit) another class I am providing (ID). These are provided in a zip file on Blackboard.  The zip also includes the javadoc generated html documentation for the classes. Your Score class should include static constants for minimum and maximum score, and minimum and maximum difficulty level, and instance variables for: (when the score was earned) – month, date, and year, and the score earned, and the highest level reached in the game.  It should also provide the at least the following methods:

·         2 constructors – the default, and one that is passed values for all 5 instance variables.

·         Simple inspectors for instance variables – score and highest level reached

·         A pseudo inspector that reports the date of the score in a normal human form – e.g. 4/3/2009

·         Simple mutators for all 5 instance variables. Each should check the passed value, and if valid set the appropriate instance variable to the passed value and return true (return false if invalid). Valid values are:

o    Month – 1-12

o    Date – 1-31

o    Year – 1995-2010

o    Score – 0-30000

o    Level Reached – 0-10

·         A controlled mutator to change the date – passed month, day, and year – so it can check the month day combination (ignore leap year)

·         A toString method that turns a Score into a reasonable String representation of a Score.  

The Player class has its instance variables declared already. These include an player ID that uses the provided ID class, a last and first name, a current handicap, and an ArrayList of Scores that holds the Player’s score info to enable keeping stats. Some methods are already provided. You need to add:

·         3 non-default constructors – one that is passed just the last name and first name; one that is passed the last name, first name, and current handicap; and one that is passed the last name, first name, current handicap and length of the employee ID. The later 2 constructors need to check that passed values are valid. If the handicap is invalid, let it remain the default value.  If the player ID length is 3 or less, use 8 as the length. (Using the proper ID constructor will automatically create random employee ID numbers with check digits).

·         4 basic inspectors

·         6 pseudo inspectors that report 1) players whole name, 2) number of scores, 3) highest score, 4) total of scores, 5) average score, 6) highest level, Hint: to loop through ArrayList elements, I recommend a “foreach” loop.

·         Basic mutators

·         A controlled mutator to change the players handicap based on how good they are. YOU decide the best way to do this. 

·         A nice, friendly toString method that shows player ID, name, current handicap, and all of the work info by Score (with all score info, date etc).

The user specifies general employee info first, then moves into score by score information. See my simple sample interface below – But don’t let that constrain your creativity. Use it to help understand what I see as the inputs and outputs. The paper version of this assignment shows a couple of screen shots from different points running my program. The version on my www site shows many screen shots from various points. We definitely want to control what the user can do at any given time (mostly by enabling and disabling buttons and jTextFields and jPanels). Details are given below. You should create buttons to:

1.      Start a new player – will generate an player Id and check that the current handicap is valid. If valid, make the rest of the GUI available and disable new player capabilities

2.      Update – adds a new score to the player’s score info based on the info specified by the user (check if valid first). Display info for the score (continued) in a jTextArea

3.      Auto-Handicap – change the players handicap

4.      See totals – see current info about the player, including summary information

5.      Clear All – put GUI back in the condition it was at the start. AND, any variables global to the GUI class should be set back to their initial value as well.

6.      Write Results – capability removed – no longer required

7.      Exit – quits the demo.

 

User Interface:

·         You’re just a beginning at setting up GUIs in NetBeans. Don’t worry too much about making the interface nice.  See my simple sample interface below – Don’t let that constrain your creativity. I know that mine can be improved upon!!! Use it to help understand what I see as inputs and outputs. The version of the assignment on my www site includes more pictures (“screen shots”). The version on Blackboard may not include any.

·         Include your name in a label or the title bar on your GUI form  

 

Miscellaneous Details:

 

Good Programming Practices:

o    MAKE SURE YOUR PROGRAM WORKS! (i.e. gets correct results).  It must provide all of the requested capabilities AND provide them in the expected way.   

o    We are now branching – so the program must be tested on more inputs to ensure that all paths through the program code work!     

·         Add YOUR NAME, e-mail address, and purpose of the program in comments at the beginning of your file (the date should already be there – which is also a very good practice). The purpose should be what the program is supposed to do, not the learning goals.

·         Name all variables and constants meaningfully.

·         Name meaningfully all jbuttons, jtxtfields, jlabels, etc that will be referred to in code. Use conventions for the start of their names.

·         Any outputs on the form itself, should be read-only. (not editable)

·         Define numbers (especially those that could change sometime in the future) as named constants (i.e. they should be ‘final’). You can use public constants from the Applicant class via the class name (e.g. Applicant.MAX_GPA)

·         Only variables that need to be accessed from more than one button  should be declared as instance variables for the GUI class. Others should be declared local to the methods they are used in.

·         Indent to show any structure of the program (The IDE usually does this well if you don’t go back and change things – probably not much to worry about on this basic of a program)

o    You MUST include some comments that explain your program in order to get full credit; any complexity should have comments – if you had to stop and think about how to do something, it needs a comment.

 

Red Tape to Aid Grading:

·         Please set the name of the project to something other than the default name (JavaApplication1, …). 

·         Add  your name in a jlabel on the GUI form or on the title bar.

 

Hand in:

 

Do your own assignments !!!!  Work that is copied or done with somebody (when not assigned to a group) will be punished. If programs are copied, both students will receive a zero for the assignment. If significant sections of programs are copied, points will be taken off. Changing small aspects of a copied program does not make it not a copy. Asking another for help on a step or two in a many-step assignment is acceptable; looking at another person’s program is temptation for cheating; handing in a near duplicate program is cheating


Sample Interface:

 

At Startup:

 

 


Invalid Input:

 

 


Starting a Player

 

 


Invalid Inputs:

 

 

 

 


Valid Update:

 

 


Another Update:

 

 


Preparing Third Update:

 

 

See Totals:

 

 


Clear: