Java Reference
In-Depth Information
/** Convert from meters to feet */
public static double
meterToFoot(
double
meter)
The formula for the conversion is:
meter = 0.305 * foot
foot = 3.279 * meter
Write a test program that invokes these methods to display the following tables:
Feet
Meters
|
Meters
Feet
1.0 0.305
| 20.0
65.574
2.0 0.610
| 25.0
81.967
...
9.0 2.745
| 60.0 196.721
10.0
3.050
| 65.0 213.115
5.10
(
Use the
isPrime
Method
) Listing 5.7, PrimeNumberMethod.java, provides the
isPrime(int number)
method for testing whether a number is prime. Use this
method to find the number of prime numbers less than
10000
.
5.11
(
Financial application: compute commissions
) Write a method that computes the
commission, using the scheme in Programming Exercise 4.39. The header of the
method is as follows:
public static double
computeCommission(
double
salesAmount)
Write a test program that displays the following table:
Sales Amount Commission
10000 900.0
15000 1500.0
...
95000 11100.0
100000 11700.0
5.12
(
Display characters
) Write a method that prints characters using the following
header:
public static void
printChars(
char
ch1,
char
ch2,
int
numberPerLine)
This method prints the characters between
ch1
and
ch2
with the specified num-
bers per line. Write a test program that prints ten characters per line from
1
to
Z
.
Characters are separated by exactly one space.
*5.13
(
Sum series
) Write a method to compute the following series:
1
2
+
2
3
+
c
+
i
m
(
i
)
=
i
+
1
Write a test program that displays the following table:
i
m(i)
1
0.5000
2
1.1667
...
19 16.4023
20
17.3546