CSC211-101   Homework 2 – Numerical Data

Due:  Tuesday, September 27, 2005

 

The United States Chess Federation (USCF) rates players who play in USCF sanctioned tournaments.  You gain or lose rating points by playing a game against an opponent. How many points you gain or lose depends on your rating before the game, your opponents rating before the game, and the outcome of the game. A game can have one of three outcomes: win, lose, or draw.

 

The actual formula used by the USCF to compute the change in a players rating is fairly involved.  However, a good approximation can be obtained by using the following formula:

 

Change in Rating = 

 

Where:

R1 =  your current rating, 

R0 =  your opponents current rating,

R  =  1.0 for a win,  0.5 for a draw,  or 0 for a loss, and

C  =  0.5 if  R1 > 1400,  0.7 if  1200 < R1 <= 1400,  or  1.0 if  R1 <= 1200.

 

Write a Java program that prompts the user for: his (or her) current rating, his (or her) opponents current rating, and the result of the game (W, D, or L).  Your program should output three quantities:  Your rating before the game is played, the change in your rating, and your new rating (after the game).  Ratings are always integers (new ratings are rounded up to the nearest integer).  Change in Rating should be formatted to one decimal place accuracy.

 

Write two separate programs:

  1. Rating.java - Use the Scanner class (with System.in) to perform all input
    and use System.out for output.
  2. Rating2.java - Use GUI's (i.e., JOptionPane) to perform all I/O.

Notes:

  1. When evaluating the expression for Change in Rating pay attention to Operator Precedence.
  2. The Conditional operator ( ?  : ) can be used to evaluate R and C. 
    The Conditional operator is second from the bottom in the Precedence Table.

 

Here's the result of one run of my Scanner version of the problem:

 

Enter your current rating: 2053

Enter your opponents rating: 1735

Enter result of game (W for win, D for draw, L for loss): D

 

Rating before game:  2053

Rating change:  -5.8

New rating:  2048

 

 

And here's the result of one run of my GUI version:

 

 

 

 

 

 

Zip your two .java programs into one .zip file and submit according to Project Submissions.