Computer Science A - Mrs. Bucaria

Problem 1 - Pythag.java
Problem: The Pythagorean Theorem states that the sum of the squares of the sides of a right triangle is equal to the square of the hypotenuse. For example, if two sides of a right triangle have lengths 3 and 4. The integers 3,4,and 5 together form a Pythagorean triplet. There is an infinite number of such triples.

Given two positive integers, m and n, where m > n, a Pythagorean triple can be generated by the following formulas:

side One = m2- n2

side Two = 2 * m * n

hypotenuse = m2 + n2

Write a Java program that asks the user for integer values m and n such that m > n and prints the values of the Pythagorean triplet generated by the formulas above.You may ASSUME the user inputs correct values, since we have not learned the conditional statement yet.

You must run the program at least three times and submit a copy of the program and a copy of three outputs.

Hint: This problem does not use the Pythagorean theorem

Problem 2 - Flight.java

Write a program for air travelers that allows the user to enter the altitude at which they are flying and reports the distance they can see (assuming aunlimited visibility). For instance, from 5,000 feet we can see a city 86 miles away.

Math hints: The solution involves the Pythagorean theorem - in a right triangle:

a2 + b2 = hypotenuse2

so that

a=sqrt(hypotenuse2 - b2)

Fact - the diameter of the Earth is 7,920 miles

Completing the above two program successfully will be a score of 90. To get higher than that the following is an extra program. Call it Quadratic.java.

Write a program called Quadratic that will enter the integer coefficients of a quadratic equation A, B and C and also one value of x to evaluate the equation at. If A=2 and B=3 and C=5 and x=2 the output would look like.

You entered y=2x^2 + 3x + 5

If x=2 y=19