Allan Didier

Computer Science Teacher

# Fractions

#### Goals

Write a Java program the can do more complex math calculations.

#### Skills

• Casting variables
• Modulus and remainder
• Output with Strings and numbers
• Math library

#### Program Details

1. Prompt the user to enter two integers, x and y.
2. Calculate and print the following:
1. The decimal equivalent of the fraction x / y.
2. The quotient and the remainder of the fraction x / y. For example if x = 50 and y = 7, your program should report that 50 / 7 is 7 with a remainder of 1 (or 7 + 1/7).
3. The absolute value of x – y
4. The exponential x raised to the y power.
5. The square root of x times y.
3. Make sure to test with numbers that will generate whole-number and decimal fractions (i.e. 4 /2 = 2.0 and 5 / 2 = 2.5), negative numbers, and zero as the denominator.

#### Hints

• Page 86-87 Conversion Techniques
• Cast one of the integers as a floating point number.

#### Resources

Edhesive Term 1

Lesson 6: Casting Variables

Lesson 7: Remainder and Modulus

Lesson 8: Output Strings and Numbers

Lesson 9: Import Math Class

Lesson 10:  Roundoff Error

Bill Barnum’s AP Computer Science A test prep videos