Java Reference
In-Depth Information
7. Write a method that takes as input the speed of a car and the duration of the trip.
The method should return the distance that is traveled.
8. Consider the following definition:
double x = 32.3947;
double y = 11.82714;
What is the result of executing the following statements?
(a) System.out.printf(”%.3f
\
n”, x);
(b) System.out.printf(”%.3f
\
n”, y);
\
(c) System.out.printf(”%.1f
n”, x);
(d) System.out.printf(”%.1f
\
n”, y);
9. Write a method that computes the n th Fibonacci number.
10. Write a method that computes n !, that is n factorial.
11. Write a method that takes as input a double and prints the value in the format
$
***,***.**. If a digit is not present, do not display anything.
4.11 Lab
Write a program that displays a triangle of random numbers (each number should be
between 0 and 9). The height of the triangle should be user specified.
Here are two example runs of the program, where user input is in italic.
Enter height of triangle:
5
4
334
46754
345
5
Enter height of triangle:
3
1
23
6
Create several methods. You should have a method that returns a random digit. You should
also have a method that prints a line, where the size of the line should be a parameter.
4.12 Project
Modify the Trading Game and add two cities: New York and Los Angeles. The price of
apples and pears changes every day in both cities. The player can only buy or sell goods
 
Search WWH ::




Custom Search