Scott Grissom
School of Computing & Info Systems
Grand Valley State University
picture

Lab: Clocks and Dice

Preparation

Do the following before arriving at lab:

  • Read chapter 3.1 - 3.10
  • Bring your textbook to lab

Objectives

After completing this lab, you should be able to:

  • invoke internal and external methods
  • write if statements to solve a problem

Exercises

Read Chapter 3 and perform each of the following exercises. Write your responses to any questions on this paper.

  1. Open the Clock-Display project in Chapter 3
  2. Add your name as author
  3. Modify the updateDisplay ( ) method to display the time as a 12 hour clock using am and pm. DO NOT change the values of any of the fields.
    00:15 becomes 12:15 am
    08:20 becomes 8:20 am
    12:30 becomes 12:30 pm
    16:40 becomes 4:40 pm
  4. When finished, show your instructor.
  5. Print the modified source code (with your name).

You will now work on a separate project involving Dice.

  1. Connect to the R: drive in the CSIS folder.
  2. Open the Dice-Games project using BlueJ
  3. Save the project to your N: drive (pay attention to where you save it).
  4. Create a new class called Triplets
  5. Define three instance variables of type Dice.
  6. Implement the following methods:
  • public Triplets ( ) - instantiate the dice in this constructor.
  • public void play ( ) - roll all dice. If all three dice values match, print "Three of a kind". If only two values match, print "Two of a kind". If all three values are different, print "Three singles". The goal is to keep this method as short as possible with elegant but readable code.
  1. When finished, show your instructor the working code.
  2. Print the source code (with your name).
Sample Output

2 4 1: three singles
3 5 5: two of a kind
4 4 4: three of a kind

Grading Criteria

This lab is worth a possible 10 points.

  • Clock Display source code (5 pts)
  • Triplets source code (5 pts)