This is a segment of our code from the lab:
public int findGCD()
{
int gcd = numerator;
if(numerator > denominator)
{
gcd = denominator;
while(numerator%gcd != 0 || denominator%gcd != 0)
{
gcd--;
}
}
{
int gcd = numerator;
if(numerator > denominator)
{
gcd = denominator;
while(numerator%gcd != 0 || denominator%gcd != 0)
{
gcd--;
}
}
Before, the || sign was an &&, and we simply could not figure out why jGRASP kept returning 0/1 or 1/1 for the GCD when we input fractions that needed to be simplified. 0 and 1 are two of the most common GCD's when simplifying, and it makes sense in a context like this. For instance, if the fraction we entered was 16/8, the program could only increment downward if BOTH of the numbers' remainders were not 0.
Overall, as I'm preparing for the test, I find that it's better to review all of the worksheets and quizzes in order to remember all of the information. The labs are also going to be a good source of studying because they contain a lot of the curriculum that we are learning in class. Hopefully, I can apply the information in the lab to the test.
No comments:
Post a Comment