-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainThread.java
More file actions
123 lines (97 loc) · 3.07 KB
/
MainThread.java
File metadata and controls
123 lines (97 loc) · 3.07 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
public class MainThread extends Thread {
public static int amount = 0;
public static void main(String[] args) {
MainThread thread = new MainThread();
thread.start();
while(thread.isAlive())
System.out.println("Waiting...");
System.out.println("Main: " + amount);
amount++;
System.out.println("Main: " + amount);
}
public void run(){
amount++;
}
} */
/*
public class MainThread implements Runnable {
public static int amount = 0;
public static void main(String[] args) {
MainThread obj = new MainThread();
Thread thread = new Thread(obj);
thread.start();
while(thread.isAlive())
System.out.println("Waiting...");
System.out.println("Main: " + amount);
amount++;
System.out.println("Main: " + amount);
}
public void run(){
amount++;
}
} */
/*
import java.util.ArrayList;
import java.util.function.Consumer;
public class MainThread {
public static void main(String[] args) {
ArrayList<Integer> nums = new ArrayList<Integer>();
nums.add(1);
nums.add(2);
nums.add(3);
Consumer<Integer> method = (n) -> { System.out.println(n); };
nums.forEach(method);
}
} */
/*
interface StringFunction {
String run(String str);
}
public class MainThread {
public static void main(String[] args) {
StringFunction exclaim = (s) -> s + "!";
StringFunction ask = (s) -> s + "?";
printFormatted("Hello", exclaim);
printFormatted("Hello", ask);
}
public static void printFormatted(String str, StringFunction format) {
String result = format.run(str);
System.out.println(result);
}
} */
import java.util.*;
interface LastName {
String write(String fname, String lname);
}
public class MainThread {
public static void main(String[] args) {
ArrayList<String> children = new ArrayList<String>();
Scanner input = new Scanner(System.in);
System.out.print("What is your last name? ");
String lastNm = input.nextLine();
System.out.print("How many children do you have? ");
int childrenCnt = input.nextInt();
if (childrenCnt == 0)
System.out.println("No Children!");
else {
System.out.println();
for (int count = 1 ; childrenCnt >= count ; count++) {
System.out.print("Enter the name of your no." + count + " child: ");
String childrenNm = input.next();
LastName fullName = (f, l) -> f.concat(" " + l);
children.add(writefn(childrenNm, lastNm, fullName));
}
}
System.out.println("\nCHILDREN: ");
for (String fn : children)
System.out.println(fn);
System.out.println("\nCHILDREN: (Alphabetical order)");
Collections.sort(children);
for (String fn : children)
System.out.println(fn);
}
public static String writefn(String firstn, String lastn, LastName fulln) {
return fulln.write(firstn, lastn);
}
}