EJERCICIOS VECTORES Y MATRICES – Libro de Tony Gaddis
1. Rainfall Class
Write a RainFall class that stores the total rainfall for each of 12 months into an array of
doubles. The program should have methods that return the following:
total rainfall for the year
the average monthly rainfall
the month with the most rain
the month with the least rain
Demonstrate the class in a complete program.
Input Validation: Do not accept negative numbers for monthly rainfall figures.
6. Driver’s License Exam
The local driver’s license office has asked you to write a program that grades the written portion of
the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct
answers:
1. B 6. A 11. B 16. C
2. D 7. B 12. C 17. C
3. A 8. A 13. D 18. B
4. A 9. C 14. A 19. D
5. C 10. D 15. D 20. A
A student must correctly answer 15 of the 20 questions to pass the exam.
Write a class named DriverExam that holds the correct answers to the exam in an array field.
The class should also have an array field that holds the student’s answers. The class should
have the following methods:
passed. Returns true if the student passed the exam, or false if the student failed
totalCorrect. Returns the total number of correctly answered questions
totalIncorrect. Returns the total number of incorrectly answered questions
questionsMissed: An int array containing the question numbers of the questions that
the student missed
Demonstrate the class in a complete program that asks the user to enter a student’s answers, and
then displays the results returned from the DriverExam class’s methods.
Input Validation: Only accept the letters A, B, C, or D as answers.
8. Grade Book
A teacher has five students who have taken four tests. The teacher uses the following grading
scale to assign a letter grade to a student, based on the average of his or her four test scores.
Test Score Letter Grade
90–100 A
80–89 B
70–79 C
60–69 D
0–59 F
Write a class that uses a String array (or an ArrayList object) to hold the five students’names, an
array of five characters to hold the five students’ letter grades, and five arrays of four doubles
each to hold each student’s set of test scores. The class should have methods that return a specific
student’s name, average test score, and a letter grade based on the average.
Demonstrate the class in a program that allows the user to enter each student’s name and his or
her four test scores. It should then display each student’s average test score and letter grade.
Input validation: Do not accept test scores less than zero or greater than 100.
11. ArrayOperations Class
Write a class name ArrayOperations with the following static methods:
getTotal. This method should accept a one-dimensional array as its argument and
return the total of the values in the array. Write overloaded versions of this method that
work with int, float, double, and long arrays.
getAverage. This method should accept a one-dimensional array as its argument and
return the average of the values in the array. Write overloaded versions of this method
that work with int, float, double, and long arrays.
getHighest. This method should accept a one-dimensional array as its argument and
return the highest value in the array. Write overloaded versions of this method that work
with int, float, double, and long arrays.
getLowest. This method should accept a one-dimensional array as its argument and
return the lowest value in the array. Write overloaded versions of this method that work
with int, float, double, and long arrays.
Demonstrate the class in a complete program with test data stored in arrays of various data types.