Function Lab 1 Write a program that includes a void method called

advertisement
Function Lab 1
1. Write a program that includes a void method called showHealthStatus that displays health
status given the BMI as follows:
BMI
Weight Status
Below 18.5
Underweight
18.5 – 24.9
Normal
25.0 – 29.9
Overweight
30.0 and Above
Obese
2. Write a program that includes a value-returning method called totalInches that converts feet
and inches to total inches. For example: 5'8"' would be converted to 68 inches.
3. Write a program that inputs heights and weights and includes methods to validate each.
4. Write a program that repeatedly inputs heights and weights and calculates bmi and shows the
health status, using the methods created above.
5. Write a value-returning method, isVowel, that returns the value true if a given character is a
vowel, and otherwise returns false. Include the method in a program that prompt the use to
input a sequence of characters and outputs the number of vowels.
6. 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 the 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.
f.
7. 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 =
8. Modify the Geometry calculator that you worked on before to include methods and the use of
dialog boxes.
Download