Using Classes and Objects(2)

Using Classes and Objects(2) - Chapter 3 Using Classes and...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 3: Using Classes and Objects (2) Lab Exercises Topics Lab Exercises Enumerated Types Playing with Cards (required) Panels Nested Panels (required) Wrapper Classes Experimenting with the Integer Class (extra credit) Formatting Classes Formatting Output (extra credit) 34 Chapter 3: Using Classes and Objects
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Playing With Cards Write a class that defines an enumerated type named Rank with values ace, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king. The main method should do the following: 1. Declare variables highCard , faceCard , card1 , and card2 of type Rank. 2. Assign highCard to be an ace, faceCard to be a jack, queen or king (your choice), and card1 and card2 to be two different numbered cards (two through ten - your choice). 3. Print a line, using the highCard and faceCard objects, in the following format: A blackjack hand: ace and . .... The faceCard variable should be printed instead of the dots. 4. Declare two variables card1Val and card2Val of type int and assign them the face value of your card1 and card2 objects. Use your card1 and card2 variables and the ordinal method associated with enumerated types. Remember that the face value of two is 2, three is 3, and so on so you need to make a slight adjustment to the ordinal value of the enumerated type. 5. Print two lines, using the card1 and card2 objects and the name method, as follows: A two card hand: (print card1 and card2) Hand value: (print the sum of the face values of the two cards) 35 Chapter 3: Using Classes and Objects
Background image of page 2
Nested Panels The program NestedPanels.java is from Listing 3.8 of the text. Save the program to your directory and do the following: 1. Compile and run the program. Experiment with resizing the frame and observe the effect on the components. 2. Modify the program by adding a third subpanel that is twice as wide, but the same height, as the other two subpanels. Choose your own label and color for the subpanel (the color should not be red, green, or blue). Add the
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/31/2010 for the course CPSC 1301 taught by Professor Khan,s during the Spring '08 term at Columbus State University.

Page1 / 6

Using Classes and Objects(2) - Chapter 3 Using Classes and...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online