Description
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:
- the 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.
Payroll Class:
Write a Payroll class that uses the following arrays as fields:
* employeeId. An arrray of seven integers to hold employee identification numbers. The
array should be initialized with the following numbers:
5658845 4520125 7895122 8777541
8451277 1302850 7580489
- hours. An array of seven integers to hold the number of hours worked by each employee
- payRate. An array of seven doubles to hold each employeeâs hourly pay rate
- wages. An array of seven doubles to hold each employeeâs gross wages.
The class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeId array. That same employeeâs pay rate should be stored in element 0 of the payRate array.
In addition to the appropriate accessor and mutator methods, the class should have a method that accepts an employeeâs identification number as an argument and returns the gross pay for that employee.
Demonstrate the class in a complete program that displays each employee number and asks the user to enter that employeeâs hours and pay rate. It should then display each employeeâs identification number and gross wages.
Input Validation: Do not accept negative values for hours or numbers less than 6.00 for pay rate.
Lottery Application:
Write a Lottery class that simulates a lottery. The class should have an array of five integers named lotteryNumbers. The constructor should use the Random class (from the Java API) to generate a random number in the range of 0 through 9 for each element in the array. The class should also have a method that accepts an array of five integers that represent a personâs lottery picks. The method is to compare the corresponding elements in the two arrays and return the number of digits that match. For example, the following shows the lotteryNumbers array and the userâs array with sample numbers stored in each. There are two matching digits (elements 2 and 4).
lotteryNumbers array:
(7, 4, 9, 1, 3)
user's array:
(4, 2, 9, 7, 3)
In addition, the class should have a method that returns a copy of the lotteryNumbers array.
Demonstrate the class in a program that asks the user to enter five numbers. The program should display the number of digits that match the randomly generated lottery numbers. If all of the digits match, display a message proclaiming the user a grand prize winner.
2D Array Operations:
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods:
- getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array.
- getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array.
- getRowTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the sub- script of a row in the array. The method should return the total of the values in the specified row.
- getColumnTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the sub- script of a column in the array. The method should return the total of the values in the specified column.
- getHighestInRow. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the highest value in the specified row of the array.
- getLowestInRow. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the sub- script of a row in the array. The method should return the lowest value in the specified row of the array.
Demonstrate each of the methods in this program.
Lo Shu Magic Square:
The Lo Shu Magic Square is a grid with 3 rows and 3 columns, shown in Figure 7-31. The Lo Shu Magic Square has the following properties:
- The grid contains the number 1-9 exactly
- The sum of each row, each column and each diagonal all add up to the same number(the number the add up to is 15). This is shown in Figure 7-32.
In a program you can simulate a magic square using a two-dimensional array. Write a method that accepts a two-dimensional array as an argument, and determines whether the array is a Lo Shu Magic Square. Test the function in a program.








