-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathPricelessScript.java
More file actions
45 lines (37 loc) · 1.7 KB
/
PricelessScript.java
File metadata and controls
45 lines (37 loc) · 1.7 KB
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
41
42
43
44
45
import java.text.NumberFormat;
public class PricelessScript {
/**
* Proof that MasterCard marketing is in your DNA
* @param args Command line arguments [The source file path, The target file path, ...]
**/
public static void main(String[] args) {
// String variables, some with format specifiers
String scriptTemplateLine1 = "%d tickets: %s";
String scriptTemplateLine2 = "%d hotdogs, %d popcorn, %d sodas: %s";
String scriptTemplateLine3 = "1 autographed baseball %s";
String scriptTemplateLine4 = "real conversation with 11 year old son: %s";
String priceless = "priceless";
// integer variable
int people = 2;
// 32 bit floating point variable
float ticketPrice = 14.0f; // 32 Bit, but it does exist!
// double precision floating point variable
double itemPrice = 9.0; // Double precision
// boolean variable
boolean trueOrFalse = true;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
System.out.println(
String.format(scriptTemplateLine1, people,
formatter.format(people * ticketPrice)));
// Example of using printf and platform specific line separator "%n" to
// format instead of String.format
System.out.printf((scriptTemplateLine2) + "%n", people, people, people,
formatter.format(people * itemPrice));
itemPrice = 45.0;
System.out.println(
String.format(scriptTemplateLine3, formatter.format(itemPrice)));
System.out.println(
String.format(scriptTemplateLine4, priceless));
System.out.println(trueOrFalse);
}
}