forked from Apress/functional-interfaces-in-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSect2_Ex1.java
More file actions
41 lines (39 loc) · 1.37 KB
/
Sect2_Ex1.java
File metadata and controls
41 lines (39 loc) · 1.37 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
package chapter7;
import java.util.function.Supplier;
import java.util.Scanner;
public class Sect2_Ex1
{
public static void main(String[] args)
{
Supplier<Integer> selectOperation = () -> {
int operation = 0;
Scanner userInput = new Scanner(System.in);
while (operation < 1 || operation > 4)
{
System.out.println("Select an operation:");
System.out.println(" 1: Operation 1");
System.out.println(" 2: Operation 2");
System.out.println(" 3: Operation 3");
System.out.println(" 4: Quit");
operation = Integer.parseInt(userInput.nextLine());
if (operation < 1 || operation > 4)
System.out.println("Invalid operation");
}
return operation;
};
boolean done = false;
while (!done)
{
switch (selectOperation.get())
{
case 1: System.out.println("Performing Operation 1");
break;
case 2: System.out.println("Performing Operation 2");
break;
case 3: System.out.println("Performing Operation 3");
break;
default: done = true;
}
}
}
}