-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringargs2.java
More file actions
40 lines (32 loc) · 992 Bytes
/
stringargs2.java
File metadata and controls
40 lines (32 loc) · 992 Bytes
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
37
38
39
40
package e_stringArgs;
import java.util.Scanner;
public class stringargs2 {
public static void main(String[] args) {
if (!(args.length >0) ) {
System.err.println("no args given");
System.exit(-1);
}
// declare
double width = 0.0, length = 0.0, sqm = 0.0, distance =0.0, tf = 0.0;
// gather input values
length = Double.parseDouble(args[0]);
width = Double.parseDouble(args[1]);
distance = Double.parseDouble(args[2]);
// calculations
sqm = length * width;
if (distance < 10 ){
tf = 0.0;
System.out.println("Travel fee is free");
} else if (distance > 10 && distance <20) {
tf = 10.0;
System.out.println("Travel fee is $10");
} else {
tf = 20.0;
System.out.println("Travel fee is $20");
}
// output
System.out.println("Length "+length + ", Width " + width + ", Sqm " + sqm);
System.out.println("Distance " + distance);
System.out.println("Travel Fee " + tf);
}
}