0% found this document useful (0 votes)
0 views

Exploring the Math Class

Uploaded by

huang54778
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Exploring the Math Class

Uploaded by

huang54778
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Unit 2: Using Objects

Coding Project

Exploring the Math Class


You are going to write a program that uses the Math methods that are available in the java.lang package.
You can view all the methods in this class here, on the oracle website. The methods in your notes are what you
will need to know on the AP exam, but you will be using some methods in this project to see what else you can
use in the Math Class.

 Display a randomly generated integer between -20 and 20 and then display the absolute value of that
number.
 Randomly generate an angle measure (as an integer) between 0 and 90 and display the three
trigonometric identities (sine, cosine, and tangent) of those angles.
 Ask the user to enter in three integers a, b, and c for a quadratic equation 𝑎𝑥 2 + 𝑏𝑥 + 𝑐 = 0 and report
both solutions. Assume the user will enter in three non-zero integers that will not result in an imaginary
solution.
 Ask the user to enter in the radius of a circle (as a decimal) and print off the circumference and area of
that circle. Use Math.PI to represent π in your equation.
 Randomly generate a decimal between 0 and 9 and round it three different ways:
o Using printf("%.0f", number)
o Using Math.round(number)
o Using (int)(number + 0.5)

Sample Run:
First Random Number: -8
Absolute Value: 8

The random angle is: 50


Sine: -0.26237485370392877
Cosine: 0.9649660284921133
Tangent: -0.27190061199763077

Enter in a: 2
Enter in b: 10
Enter in c: 5
The first solution is: -0.5635083268962915
The second solution is: -4.436491673103708

Enter in the radius of your circle: 3.5


Circumference of circle: 21.991148575128552
Area of circle: 38.48451000647496

6
6
6

You might also like