Lab 3

Purpose

This lab introduces you to basic Java classes. It is important for you to understand the basics of class setup. This lab is designed to give you experience writing a class (declaring variables, writing constructors and methods) and also using classes (declaring objects, calling methods, and using return values)

Key Reading

  • 3.3-3.6
  • 4.1-4.5

Introduction

IACP

The IACP (International Association of Checkers Players) is working on some software to simulate checkers games. They have completed a class (CheckersTable.java) that will simulate the board and can handle much of the logic for the simulation of a game. They need your help to write a class (Contestant.java) that will store information about each contestant and another class that will give and receive information from a user.

The IACP has given you API style documentation for two classes: Contestant.java and CheckersTable.java. Read through these carefully before you start to do any coding for this lab.

Requirements

The API documentation for Contestant.java and CheckersTable.java can be found here.

A zip folder with the necessary files to complete this lab can be downloaded here. This file contains an Eclipse project that you can import to complete your lab. The project includes CheckersTable.java already. Do not modify CheckersTable.java in any way. This file has purposefully been made difficult to read. It is not recommended that you look at the source code to try to understand the workings of this class. The API documentation should be sufficient for your needs.

Part 1 - Get in the Game (15 points)

  • Write Contestant.java. Your class must be named Contestant.java and must have the methods specified in the API documentation.
  • You receive 2 points per method (7 methods in total) or 15 points for a fully functional class

Part 2 - Going for the Win (15 points)

  • Write a class that will do the following
    • Prompt the user for information about two different contestants and create two objects of the Contestant class using that information. Also accept a number from the user for the number of seconds that will be given to each player to complete their moves. (5 points)
    • Simulate a game using a method from the CheckersTable class. You can look at the API documentation to find a method that might help you with this. (5 points)
    • Report the winner of the game, the move history, how much time is left on the clock, and how many pieces the winner had left. (5 points)
  • This class should be your driver, meaning it contains a main method.

Requirement Notes

When writing your Contestant class, it might be useful to know that in checkers, each player starts out with 12 pieces.

API Documentation

The information about CheckersTable.java was given to you so that you can know what methods have been written in this class and how you can use them. This class has already been written for you and can be downloaded in the zip file mentioned above.

The information about Contestant.java has been given to you as a guide to use when you write this class. As you write the code for Contestant.java, be sure that you include all the methods in the documentation for the class (see link above). You also need to be sure that the parameters and return types for each method are the same as specified in the documentation.

Having trouble understanding how to go from the API documentation to code? Click here to look at some API documentation for Die.java which is in your book. Remember, you do not need to write any code for Die.java and it is not part of the lab. This is just supplied to help you understand how to to look at the API documentation for Contestant.java and know how to start writing code for those methods.

Zip Files

You will need the files from lab3.zip. To do this, first download the zip folder using the above link. Then open up the zip folder and copy the lab 3 folder onto your F: drive in the same location as the folders you have for your other labs.

Jar Files

CheckersGame.jar is a working copy of the program that you can use to help you understand how your program should work. To use this jar file you must first open a command prompt. In that command prompt, navagate to the folder in which you have put the CheckersGame.jar file. Once you have navagated there, type in the following command java -jar CheckersGame.jar

Designed by Andy Griffin