10/18/2006 Update

The due date for this assignment has been extended by one week. The assignment is now due 11pm the day prior to week 9 lab. In addition to the original assignment (left intact below), you are required to fix any problems identified in the Fraction class implementation submitted for the lab 4 assignment.

Outcomes Addressed

Overview

Develop a simple game using fractions.

Details

Modifications to the Fraction Class

You should make the following modifications to your Fraction class:

The Game

You should write a program that generates a fraction with a value between -1 and 1, called computerGenerated. The user should be repeatedly asked to guess the value of the computer generated fraction until the user's guess is within 1/100th of computerGenerated. After each incorrect guess the program should indicate if the user guess a number less than or greater than computerGenerated.

Once the user has guessed sufficiently close to the computer generated value, the program should display computerGenerated. The program should then randomly select a mathematical operation (add, multiply, subtract, or divide) and ask the user to enter two fractions, frac1 and frac2, whose values are chosen such that frac1 math operation frac2 == computerGenerated.

For example, if computerGenerated == 2/7 and the randomly chosen mathematical operation is add then, the user should enter something like: 1/7 and 1/7. The user should be given as many chances as they need to enter two valid fractions. Once the user has entered two valid fractions, the user should be notified and the program should end. Here is a sample result of running the program:

Please guess a fractional number between -1 and 1: 0
That's less than what I was thinking, please guess again: 1/2
That's more than what I was thinking, please guess again: 3/8

That's correct!
Please enter two fractions, A and B, such that A * B = 3/8.
A: 3/4
B: 1/4

No.  3/4 * 1/4 = 3/16.  
Please enter two fractions, A and B, such that A * B = 3/8.
A: 3/2
B: 1/4

That's correct!  3/2 * 1/4 = 3/8
Thanks for playing.

Before you begin writing your program, you should think about all of the parts that need to be accomplished. Make a list of all of the things that need to be done. Determine what portions can be accomplished in separate methods, and design your program so that it makes use of more than just a main method. This will allow you to simplify the overall complexity of your program by breaking it into a bunch of simple methods (instead of one complicated main method).

Lab report (due 11:00pm, the day prior to week 8 lab)

Each student should indicate how much time you spend on this assignment in the FAST system. You are encouraged to log your activity as you work on the project. At a minimum, you should log all of the time spent on this assignment before the due date given above. All time spent on this assignment should be entered into the week 7 column (even if you worked on it in week 8).

Dr. Taylor's students should use this XML template as a starting point for their reports.

Each student should submit a lab report. Your report should include:

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic submission guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost.

If you have any questions, consult your instructor.

Acknowledgment

This laboratory assignment was developed by Dr. Chris Taylor.