Fractions Example
From Huben's Wiki
(Created page with "- →* Represents a fraction with an int numerator and int denominator * and provides methods for adding and multiplying fractions. * * Author: Alex: public class Fr...") |
|||
Line 120: | Line 120: | ||
} | } | ||
− | // add a main to test all of the constructors and methods and print their results | + | // add a main to test all of the constructors and methods and print their results. Update as you add methods. |
// make a toString method that converts the fraction to an "a/b" string | // make a toString method that converts the fraction to an "a/b" string | ||
// make a getValue method that returns a double with the value of the fraction | // make a getValue method that returns a double with the value of the fraction | ||
// double constructor (makes any decimal .xxx into xxx/1000, any number of xs) | // double constructor (makes any decimal .xxx into xxx/1000, any number of xs) | ||
− | |||
− | |||
− | |||
− | |||
// getNum method | // getNum method | ||
// getDenom method | // getDenom method | ||
// setNum method | // setNum method | ||
// setDenom method | // setDenom method | ||
+ | // reciprocal method | ||
+ | // subtract method (integer and fraction) | ||
+ | // divide method (integer and fraction) | ||
+ | // negate method |