Java Reference
In-Depth Information
*5.14
(
Estimate
p
)
p
can be computed using the following series:
1)
i
+
1
(
-
VideoNote
1
3
+
1
5
-
1
7
+
1
9
-
1
11
+
c
+
m
(
i
)
=
4
¢
1
-
1
≤
Estimate
p
2
i
-
Write a method that returns
m(i)
for a given
i
and write a test program that dis-
plays the following table:
i m(i)
1 4.0000
101 3.1515
201 3.1466
301 3.1449
401 3.1441
501 3.1436
601 3.1433
701 3.1430
801 3.1428
901 3.1427
*5.15
(
Financial application: print a tax table
) Listing 3.6 gives a program to compute
tax. Write a method for computing tax using the following header:
public static double
computetax(
int
status,
double
taxableIncome)
Use this method to write a program that prints a tax table for taxable income from
$50,000 to $60,000 with intervals of $50 for all the following statuses:
Taxable
Single
Married Joint
Married
Head of
Income
or
Qualifying
Separate
a House
Widow(er)
50000
8688
6665
8688
7352
50050
8700
6673
8700
7365
...
59950
11175
8158
11175
9840
60000
11188
8165
11188
9852
*5.16
(
Number of days in a year
) Write a method that returns the number of days in a
year using the following header:
public static int
numberOfDaysInAYear(
int
year)
Write a test program that displays the number of days in year from 2000 to 2020.
Sections 5.10-5.11
*5.17
(
Display matrix of 0s and 1s
) Write a method that displays an
n
-by-
n
matrix using
the following header:
public static void
printMatrix(
int
n)
Each element is 0 or 1, which is generated randomly. Write a test program that
prompts the user to enter
n
and displays an
n
-by-
n
matrix. Here is a sample run:
3
Enter n:
0 1 0
0 0 0
1 1 1