subject

This question involves computing the greatest common factor between two positive integers and using greatest common factors to reduce fractions. You will write two methods in the NumberSystem class that follows. public class NumberSystem

{

/** Precondition: a and b are positive integers.

* Returns the greatest common factor of a and b, as described in part (a).

*/

public static int gcf(int a, int b)

{ /* to be implemented in part (a) */ }

/** Precondition: numerator and denominator are positive integers.

* Reduces the fraction numerator / denominator

* and prints the result, as described in part (b).

*/

public static void reduceFraction(int numerator, int denominator)

{ /* to be implemented in part (b) */ }

}

The greatest common factor (GCF) of two integers a and b is the largest integer that divides evenly into both a and b. For example, the GCF of 8 and 12 is 4.

The greatest common factor can be computed using the following rules.

Case I: If a is evenly divisible by b, then the GCF is b.
Case II: If a is not evenly divisible by b, then the GCF of a and b is equal to the GCF of b and the remainder when a is divided by b.
If the rule in case II is repeatedly applied, it is guaranteed to eventually result in case I. Consider the following examples.

Example 1
In determining the GCF of 30 and 3, case I applies because 30 is evenly divisible by 3. Therefore, the GCF of 30 and 3 is 3.
Example 2
In determining the GCF of 3 and 30, case II applies because 3 is not evenly divisible by 30. The GCF of 3 and 30 will be equal to the GCF of 30 and the remainder when 3 is divided by 30, or 3.
In determining the GCF of 30 and 3, case I applies because 30 is evenly divisible by 3. The GCF of 30 and 3 is 3, and therefore the GCF of 3 and 30 is also 3.
Example 3
In determining the GCF of 24 and 9, case II applies because 24 is not evenly divisible by 9. The GCF of 24 and 9 will be equal to the GCF of 9 and the remainder when 24 is divided by 9, or 6.
In determining the GCF of 9 and 6, case II applies because 9 is not evenly divisible by 6. The GCF of 9 and 6 will be equal to the GCF of 6 and the remainder when 9 is divided by 6, or 3.
In determining the GCF of 6 and 3, case I applies because 6 is evenly divisible by 3. The GCF of 6 and 3 is 3, and therefore the GCF of 24 and 9 is also 3.
Example 4
In determining the GCF of 7 and 3, case II applies because 7 is not evenly divisible by 3. The GCF of 7 and 3 will be equal to the GCF of 3 and the remainder when 7 is divided by 3, or 1.
In determining the GCF of 3 and 1, case I applies because 3 is evenly divisible by 1. The GCF of 3 and 1 is 1, and therefore the GCF of 7 and 3 is also 1.

(a) The gcf method returns the greatest common factor of parameters a and b, as determined by case I and case II. Write the gcf method below. You are encouraged to implement this method recursively.

/** Precondition: a and b are positive integers.

* Returns the greatest common factor of a and b, as described in part (a).

*/

public static int gcf(int a, int b)

Question 2
In a fraction, the numerator is the number above the fraction bar and the denominator is the number below the fraction bar. A fraction can be reduced according to the following rules.

If the numerator is evenly divisible by the denominator, then the fraction reduces to the result when the numerator is divided by the denominator.
If the numerator is not evenly divisible by the denominator, then the reduced numerator will be equal to the numerator divided by the GCF of the numerator and the denominator. Similarly, the reduced denominator will be equal to the denominator divided by the GCF of the numerator and the denominator.
The reduceFraction method is intended to reduce the fraction numerator / denominator and print the result. Examples of the intended behavior of the method are shown in the table.

Method Call Message Printed Explanation
reduceFraction(30, 3) 30/3 reduces to 10 30 is evenly divisible by 3. The fraction reduces to the result 10.
reduceFraction(8, 20) 8/20 reduces to 2/5 8 is not evenly divisible by 20. The numerator and denominator are each divided by the GCF, which is 4.
reduceFraction(24, 9) 24/9 reduces to 8/3 24 is not evenly divisible by 9. The numerator and denominator are each divided by the GCF, which is 3.
reduceFraction(7, 3) 7/3 reduces to 7/3 7 is not evenly divisible by 3. The numerator and denominator are each divided by the GCF, which is 1.
(b) Write the reduceFraction method below. Assume that gcf works as specified, regardless of what you wrote in part (a). You must use gcf appropriately to receive full credit.

/** Precondition: numerator and denominator are positive integers.

* Reduces the fraction numerator / denominator

* and prints the result, as described in part (b).

*/

public static void reduceFraction(int numerator, int denominator)

ansver
Answers: 2

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 22.06.2019 11:10
5. your analysis of child assessment data shows that a few of the students in your classroom are lethargic and exhibit challenging behaviors before snack time. you note that after snack time and lunch, they're engaged and responsive. what other information might you understand why? a. attendance data, teacher observation checklists, and frequency counts b. anecdotal notations, attendance data, and child health records c. family interviews, daily health check, and behavioral logs d. standardized assessments, time samples, and conversations with other teachers
Answers: 2
question
Advanced Placement (AP), 24.06.2019 17:50
For review 1. in terms of which government is sovereign, differentiate among a unitary system, a confed- eral system, and a federal system of government. 2. to which level of government does the constitution distribute the enumerated po implied powers? concurrent powers? reserved powers? provide several power. 3. what matters fall within the scope of state sovereignty? differentiate among dual federalism, cooperative federalism, centralized federalism, and conflicted federalism. how does the national government use grants-in-aid, mandates, and preemption to direct the policy of state and local governments? 6. what do we mean by intergovernmental relations? why is the term a good description of u.s. federalism today? 7. list several advantages and several disadvantages of a federal system.
Answers: 2
question
Advanced Placement (AP), 25.06.2019 06:00
Why is it essential to operationally define the variables in a study?
Answers: 1
question
Advanced Placement (AP), 26.06.2019 03:00
Psycoloshist albert bandits developed a theory of
Answers: 2
You know the right answer?
This question involves computing the greatest common factor between two positive integers and using...
Questions
question
Mathematics, 26.07.2019 05:30
Questions on the website: 13722362