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.

- Design and document an algorithmic solution for a given problem statement
- Use if/if-else/switch statements to control program flow in algorithmic solutions
- Select the appropriate selection control statement for a given task
- Use while/do-while/for statements to control repetition in algorithmic solutions
- Select the appropriate repetition control statement for a given task
- Use existing Java class libraries
- Design and implement simple Java programs
- Test and debug code

Develop a simple game using fractions.

You should make the following modifications to your Fraction class:

- Modify your Fraction class so
that the default constructor assigns a random value between
**-1**and**1**. - Modify the constructor that takes a String so that it can handle the situation where the input string is just an integer ("3" should be interpreted as "3/1").
- Create a reduce() method that ensures that the calling object is stored in reduced form. The reduce() method should only be called by other methods from the Fraction class, so it should be declared as a private method.
- When the toString() method is used to display in fraction form, it should always display the fraction in reduced form.

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/100^{th}
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).

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:

- Sample program output for the program.
- Discussion (how you designed your program (what methods you chose to implement and why), problems you encountered (and how they were overcome), what you learned, what surprised you, etc...)
- Documented source code for your two classes.

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.

This laboratory assignment was developed by Dr. Chris Taylor.

© 2001-2006 Dr. Christopher C. Taylor | Office: CC-36C | Phone: 277-7339 |