Fractions Example
From Huben's Wiki
Line 1: | Line 1: | ||
+ | // 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 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) | ||
+ | |||
+ | // getNum method (what do we call this sort of method?) | ||
+ | |||
+ | // getDenom method | ||
+ | |||
+ | // setNum method | ||
+ | |||
+ | // setDenom method (what do we call this sort of method?) | ||
+ | |||
+ | // reciprocal method (could we make this a constructor?) | ||
+ | |||
+ | // subtract methods (integer and fraction) | ||
+ | |||
+ | // divide methods (integer and fraction) | ||
+ | |||
+ | // negate method (should we change the object or make a new one?) | ||
+ | |||
+ | |||
/* | /* | ||
* Represents a fraction with an int numerator and int denominator | * Represents a fraction with an int numerator and int denominator | ||
Line 118: | Line 143: | ||
return gcf(n % d, d % n); | return gcf(n % d, d % n); | ||
} | } | ||
− | } | + | } |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |