Java Reference
In-Depth Information
(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 com-
puted 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
]
*8.13
(
Locate the largest element
) Write the following method that returns the location
of the largest element in a two-dimensional array.
public static int
[] locateLargest(
double
[][] a)
The return value is a one-dimensional array that contains two elements. These
two elements indicate the row and column indices of the largest element in the
two-dimensional array. Write a test program that prompts the user to enter a two-
dimensional array and displays the location of the largest element in the array.
Here is a sample run:
Enter the number of rows and columns of the array: 3 4
Enter the array:
23.5 35 2 10
4.5 3 45 3.5
35 44 5.5 9.6
The location of the largest element is at (1, 2)
**8.14
(
Explore matrix
) Write a program that prompts the user to enter the length of a
square matrix, randomly fills in
0
s and
1
s into the matrix, prints the matrix, and
finds the rows, columns, and diagonals with all
0
s or
1
s. Here is a sample run of
the program:
Search WWH ::
Custom Search