Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.
Getting Ready: Before going any further, you should:
A fraction is a quotient of one integer divided by another (often indicated by a/b).
The dividend a is called the numerator and the divisor b is called the denominator. One can add a fraction to, subtract a fraction from, multiply a fraction by, and divide a fraction by another fraction. The result of each of these operations is another fraction.
toString()
method
that returns a String
representation of
an instance. For this class, how should the String
be formatted? (Note: Remember to think about the sign of the
fraction.)
Fraction
objects are supposed to be immutable,
should this class have "set" methods?
toString()
method above,
it would clearly be useful to always use positive integers for
the numerator and the denominator and keep a sign attribute.
What type should the sign attribute be and what values should
it take on? (Hint: Think about how it will be used in the
various methods.)
add()
method to
perform this other operation?
multiply()
method to
perform this other operation?
An "Esketcher" is a simple electronic drawing toy (like the
famous Etch A Sketch from The Ohio Art
Company
).
You can shake an "Esketcher", you can turn the horizontal drawing dial clockwise, you can turn the horizontal drawing dial counter-clockwise, you can turn the vertical drawing dial clockwise, and you can turn the vertical drawing dial counter-clockwise.
Copyright 2020