Issaquah High School Computer Science

Mr. Wortzman | Room 3209 | Issaquah High School, Issaquah, WA

Project 1 - Fraction Calculator

Specification

Overview

Modern computers are capable of an incredibly varied set of operations and behaviors, from analyzing data to playing movies to supporting complex three-dimensional games. At the core of all these programs, however, is the central talent of computers—- performing mathematical operations. We will utilize this basic skill to implement a calculator program that will perform a variety of operations on fractions.

Behavior

Input

Input will be in the form of a value, followed by an operators, followed by another value (e.g. “1/2 * 3/8”). Values and operators will be separated by a single space, and neither values nor operators will contain any spaces. Input values may be in the form of mixed fractions, proper fractions, improper fractions, or integers. Fractional input values need not necessarily be in lowest terms. The numerator and denominator of a fraction will be separated by a forward slash (/). The integer and fraction parts of a mixed fraction will be separated by an underscore (_) (e.g. “1_3/4” is one and three fourths, while “13/4” is thirteen fourths).

The calculator will support the four basic arithmetic operations: addition (+), subraction (-), multiplication (*), and division (/). Note that the symbol for division is the same as the symbol that separates the numerator and denominator of a fraction.

Output

The program should output the result of the calculation to the screen. Output should be in the form of the expression, and equals sign, and the result (e.g. “1/2 * 3/8 = 3/16”). The input values should be echoed in the output exactly as they were given, but the result should be an integer, proper fraction, or mixed number in lowest terms (e.g. 3/4 instead of 6/8 and 1_1/2 instead of 3/2). The result of an operation should never be an improper fraction.

Main Driver Loop

Your program should begin by welcoming the user to the program. Then, it should enter a “driver loop” that executes the various steps of the program repeatedly until the user chooses to exit. Your driver loop will operate as follows:

The program should continue through this loop until the user types “quit.” You should ignore case when checking the input (i.e. “quit,” “QUIT,” “Quit,” and “qUiT,” among others, should all end the program). Once the user types quit, the program should print a goodbye message and terminate.

Implementation Details

Code Organization

Your code must conform to the following requirements in the implementation:

Unit Testing

You will be provided with a suite of unit tests to run against your program. In order to receive full credit for any checkpoint or the final submission, your program must pass ALL relevant unit tests. Note that these tests are not exhaustive, so passing all the tests does not guarantee any particular grade. Details on importing and running the tests in jGRASP will be provided soon.

UPDATE: A baseline set of Unit Tests is now available. Follow the instructions given in class to use these to test your project.

Extra Credit

You may earn extra credit by implementing additional features beyond those that are required. Point values for extra credit features will be solely at my discretion and will be determined based on creativity and difficulty of implementation. No extra credit will be awarded for features that break required functionality, and points will still be lost for failing to meet requirements. It is HIGHLY recommended that you not attempt extra credit work until your project is fully complete. Extra credit will be capped at 10% of the total project value.

Possible extra credit features include (but are not limited to):

Note that your extra credit work must not cause any of your unit tests to fail or otherwise cause the program functionality to change. In other words, your extra credit features must not require the user to change their behavior to use the program properly– you must simply add additional, optional features.

Checkpoints

Checkpoint 1 - Parsing Input

Tuesday, December 01, 2015 (worth 10%)

main() creates a Scanner and reads one line of input; produceAnswer() breaks a single line of input into the relevant three parts, stores each part in a variable, and returns the second operand

Checkpoint 2 - Driver and Fractions

Monday, December 07, 2015 (worth 10%)

main() includes the driver loop, repeatedly accepting input and calling produceAnswer() until the user types "quit"; produceAnswer() parses each operand into three parts-- a whole portion, a numerator, and a denominator-- and returns a String describing the second operand, formatted as "whole: numerator: denominator: " (e.g. if the second operand is 3_5/8, produceAnswer() returns "whole: 3 numerator: 5 denominator: 8")

Final Due Date

Wednesday, December 16, 2015

All required program elements are implemented and functional

Rubric

Behavior
Program greets user on startup and displays a goodbye message on termination 1 points
Typing "quit" ends the program regardless of case 1 points
Program repeatedly prompts the user for an expression 1 points
Program is able to parse each line of input into three parts (value, operator, value) 2 points
Program is able to parse each fraction value into three parts (whole, numerator, denominator) 3 points
Program is able to handle integers, proper fractions, improper fractions, and mixed numbers, both positive and negative 4 points
Program output is in proper format 2 points
Output is a mixed fraction in lowest terms 4 points
Multiplication and division work correctly 3 points
Addition and subtraction work correctly 4 points
Total25 points
Implementation
main is a concise summary of program behavior 1 points
produceAnswer is implemented as required 2 points
Program uses good procedural decomposition, including parameters and return values 2 points
Program is well-documented and uses good style 2 points
Checkpoint 1 4 points
Checkpoint 2 4 points
Total15 points
Project total40 points