Method Lab 2 Given two points (x1, y1) and (x2, y2) :the distance

advertisement
Method Lab 2
1. Given two points (x1, y1) and (x2, y2) :the distance between them is defined as:
sqrt((x2-x1)2 + (y2-y1)2). Given a circle and a point on the circle, you can use the formula to find
the radius of the circle. Write a program that prompts the user to enter the center and a point
on the circle. The program should then output the circle's radius, diameter, circumference, and
area. Use the following methods:
a. distance: this method takes as its parameters four numbers that represent two points in
the plane and returns the distance between them.
b. radius: this method takes as its parameters four numbers that represent the center and
a point on the circle, calls the method distance to find the circle's radius and returns the
radius.
c. circumference: this method takes as its parameter a number that represents the radius
of the circle and returns the circle's circumference. (if r is radius, circumference is 2πr).
d. area: this method takes as its parameter a number that represents the radius of the
circle and returns the circle's area. (if r is the radius, circumference is πr2).
e. Assume that π = 3.1416.
2. Write a program that reads a student's name together with his or her test score. The program
should then compute the average test score for each student and assign the appropriate grade,
A, B, C, etc. Your program must use the following methods:
a. A value-returning method average, to determine the average of the five test scores for
each student.
b. A void method displayGrade, to display each student's grade to the file.
c. Test your program with the following data. Read the data to a file and output to a file.
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63
Sample Output: The output should be in the following form. Fill in the last two columns
and the last line showing the class average (two decimal places).
Student
Test1 Test2 Test3 Test4 Test5 Average Grade
Johnson
85
83
77
91
76
Aniston
80
90
95
93
48
…
Class Average =
Download