Java Reference
In-Depth Information
Enter a student record: Jordan 4 86 71 62 90
Jordan's grade is 77.25
Maria's grade is 82.8 because her average of (72 + 91 + 84 + 89 + 78) / 5 equals 82.8.
9.
Write the method called
printTriangleType
referred to in Self-Check Problem 22. This method accepts three
integer arguments representing the lengths of the sides of a triangle and prints the type of triangle that these sides
form. Here are some sample calls to
printTriangleType
:
printTriangleType(5, 7, 7);
printTriangleType(6, 6, 6);
printTriangleType(5, 7, 8);
printTriangleType(2, 18, 2);
The output produced by these calls should be
isosceles
equilateral
scalene
isosceles
Your method should throw an
IllegalArgumentException
if passed invalid values, such as ones where one
side's length is longer than the sum of the other two, which is impossible in a triangle. For example, the call of
printTriangleType(2, 18, 2);
should throw an exception.
10.
Write a method called
average
that takes two integers as parameters and returns the average of the two integers.
11.
Modify your
pow
method from Exercise 4 to make a new method called
pow2
that uses the type
double
for the first
parameter and that works correctly for negative numbers. For example, the call
pow2(-4.0, 3)
should return
-4.0
* -4.0 * -4.0
, or
-64.0
, and the call
pow2(4.0, -2)
should return
1 / 16
, or
0.0625
.
12.
Write a method called
getGrade
that accepts an integer representing a student's grade in a course and returns that
student's numerical course grade. The grade can be between
0.0
(failing) and
4.0
(perfect). Assume that scores are
in the range of
0
to
100
and that grades are based on the following scale:
Score
Grade
< 60
0.0
60-62
0.7
63
0.8
64
0.9
65
1.0
. . .
92
3.7
93
3.8
94
3.9
>= 95
4.0
Search WWH ::
Custom Search