(Financial application: compute tax) Rewrite Listing 1, ComputeTax.java, using arrays. For each filing status, there are six tax rates. Each rate is applied to a certain amount of taxable income. For example, from the taxable income of $400,000 for a single filer, $8,350 is taxed at 10%, (33,950 - 8,350) at 15%, (82,250 - 33,950) at 25%, (171,550 - 82,550) at 28%, (372,550 - 82,250) at 33%, and (400,000 - 372,950) at 36%. The six rates are the same for all filing statuses, which can be represented in the following array:
double[] rates = {0.10, 0.15, 0.25, 0.28, 0.33, 0.35};
The brackets for each rate for all the filing statuses can be represented in a two dimensional array as follows:
int[][] brackets = {
{8350, 33950, 82250, 171550, 372950}, // Single filer
{16700, 67900, 137050, 20885, 372950}, // Married jointly
// -or qualifying widow(er)
{8350, 33950, 68525, 104425, 186475}, // Married separately
{11950, 45500, 117450, 190200, 372950} // Head of household
};
Suppose the taxable income is $400,000 for single filers. The tax can be computed as follows:
tax = brackets[0][0] * rates[0] +
(brackets[0][1] – brackets[0][0]) * rates[1] +
(brackets[0][2] – brackets[0][1]) * rates[2] +
(brackets[0][3] – brackets[0][2]) * rates[3] +
(brackets[0][4] – brackets[0][3]) * rates[4] +
(400000 – brackets[0][4]) * rates[5]
LISTING 1 Weather.java
1 import java.util.Scanner;
2
3 public class Weather {
4 public static void main(String[] args) {
5 final int NUMBER_OF_DAYS = 10;
6 final int NUMBER_OF_HOURS = 24;
7 double[][][] data
8 = new double[NUMBER_OF_DAYS][NUMBER_OF_HOURS][2];
9
10 Scanner input = new Scanner(System.in);
11 // Read input using input redirection from a file
12 for (int k = 0; k
13 int day = input.nextInt();
14 int hour = input.nextInt();
15 double temperature = input.nextDouble();
16 double humidity = input.nextDouble();
17 data[day - 1][hour - 1][0] = temperature;
18 data[day - 1][hour - 1][1] = humidity;
19 }
20
21 // Find the average daily temperature and humidity
22 for (int i = 0; i
23 double dailyTemperatureTotal = 0, dailyHumidityTotal = 0;
24 for (int j = 0; j
25 dailyTemperatureTotal += data[i][j][0];
26 dailyHumidityTotal += data[i][j][1];
27 }
28
29 // Display result
30 System.out.println("Day " + i + "'s average temperature is "
31 + dailyTemperatureTotal / NUMBER_OF_HOURS);
32 System.out.println("Day " + i + "'s average humidity is "
33 + dailyHumidityTotal / NUMBER_OF_HOURS);
34 }
35 }
36 }

We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.