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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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.
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern