Welcome to the Fractions Calculator! > 1/2 + 3/4 5/4 > -1/2 + 3/4 1/4 > -1/2 - -3/-4 -5/4 > 123/456 * 1/1 41/152 > 123/456 * 2/1 41/76 > 41/76 / 16/8 41/152 > 1/1 - 13/7 -6/7 > 4/7 = -8/-14 0/1 > 1/2 = 4/5 1/1 > quit Goodbye. |
As its name suggests, each instance of the Fraction class represents a fraction. More precisely, it represents a common (or simple) fraction, which consists of an integer numerator and a non-zero integer denominator (and represents the ratio between those two numbers, or what is known as a rational number).
Provided to you, for the purpose of testing your work, is the application program, FractionCalculator, which is shown "in action" to the right. (User input is in boldface.) As you can see, it prompts the user to enter a simple arithmetic expression in which an operator is applied to two fractions, and it responds with the result.1
Standard computer hardware processors are designed to perform operations directly upon both integers and real numbers, the latter represented using a floating point scheme, but they do not deal directly with rational numbers.One advantage of operations on integers (vs. numbers stored in floating point notation) is that results produced are exact, assuming that they are within the range of values representable within whatever quantity of memory has been allocated to store the result. (E.g., In Java, a value of type int is restricted to being in the range -231 .. 231-1, because it is stored in a memory cell of 32 bits.)
The range (from low to high) of numbers representable using floating point notation (and the same quantity of memory) is much larger. However, operations on floating point numbers generally produce only approximate results, because of limited precision. (Loosely speaking, precision refers to the limit upon how many significant digits can be represented. Again, see Wikipedia's article on floating point arithmetic.)
Because a rational number is represented by two integers, operations performed upon such numbers need not suffer a loss of precision, as is the case with floating-point numbers.
1/2 12/4 2/8 |
1) "1/2" aka 1/2 accumulates to 1/2 2) "12/4" aka 3/1 accumulates to 7/2 3) "2/8" aka 1/4 accumulates to 15/4 The mean value is 5/4 |
As usual, the Java source code file (Fraction.java) that you submit (to the relevant Brightspace folder) must contain comments identifying all agents (i.e., persons and AI entities) with whom you collaborated and listing any defects of which you are aware.