-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableDisplay.java
36 lines (28 loc) · 1.17 KB
/
TableDisplay.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Programmer: Dan Hopp
* Date: 11-OCT-2019
* Description: Display two tables side by side. The left table will convert
* will convert meters from feet, starting at 7m and ending at 107m. The right
* table will convert feet to meters, starting at 50ft and ending at 150ft.
* Display conversions with 2 decimal points
* 1m = 3.2808ft. 1ft = 0.3048m.
*/
package lab5;
public class Problem2 {
public static void main(String[] arg) {
//declare constants
final double METERS_TO_FEET = 3.2808;
final double FEET_TO_METERS = 0.3048;
//print table header
System.out.printf("%-10s%-10s%-5s%-10s%-10s\n", "Meters", "Feet", "|",
"Feet", "Meters");
//set measurement lengths and iterate loop 10 times
for (int meters = 7, feet = 50; meters < 108;
meters += 10, feet += 10) {
//convert measurements and print table line
System.out.printf("%-10d%-10.2f%-5s%-10d%-10.2f\n", meters,
(meters * METERS_TO_FEET), "|", feet,
(feet * FEET_TO_METERS));
}
}
}