Assignment #3

 

Program #1: At least one of your metods in this program may need to be ‘static’.  Create a class called Card that represents to a deck of cards.  The card should have two fields:  number (int) and suit (String).  For Jack, use 11, Queen use 12, King use 13, and Ace, use 14.  Have all of the fields for a class as in the previous programs. In addition, have a method called ‘deal’ that returns a Card object with a random value for the number and the suit. (This will have to be a static method).  That way a user could create a new Card object of random number and suit by saying:

Card newCard = Card.deal();

 

For your mutator methods, ensure that:

-         suit can only be Hearts, Diamonds, Spades, Clubs. 

-         number should be between 2 and 14

 

Your default constructor should randomly set the face and suit of the card.

Also have a constructor that allows the user to set both the face and suit. Remember to assign those values within that constructor using your mutator methods.

 

Here is the code to randomly generate a number between 1 and 4.  Modify as needed for your program:

int x = (int) (Math.random()*4) + 1;

 

In a separate class (ie: a class that has a main() method), create an array of 52 Card objects (no Joker cards) and fill it.  You do NOT have to use the random card generator method described above to fill the deck. In other words, you can simply go through each suit and fill the deck with card numbers 2 through 14 of each.

 

Bonus up to 7 points:  Create a method called ‘shuffle’ that accepts an array of Card objects and randomly mixes those cards up so that you have a shuffled deck.

 

 

Program #2: Create a GUI in which you ask the user to enter 5 integers (in 5 different textfields).  Then have 3 buttons, one of which says ‘Find Average’, ‘Find Highest’, ‘Find Lowest’.  Also have an exit button.  When they click a button (other than exit), create an array of from the numbers entered, and output in a textfield or label somewhere, the result of their request.  You may assume the user will have always entered 5 integers as requested. For fun you can try outputting an error message if fewer than the 5 textfields are entered, but this is not required.

 

Program #3:  Create a class called Book that might be used for a library catalog.  Create fields to keep track of the author’s name, title, year of publication, and isbn number. Include all the ‘necessary’ methods for your class such as accessors, modifiers, and constructors.  You must also include a copy constructor, toString(), and equals() methods.  Besides the default and copy constructors, have at least one additional constructor.  Use ‘thoughtful’ initial values for the fields inside your default constructor.

 

 

Assignment and Submission Guidelines:

-          Remember that all user-defined classes must have the usual methods (copy constructor, toString, etc).

-          Submit all of your source code files as a ZIP file.