-
Notifications
You must be signed in to change notification settings - Fork 6
/
Menu.java
46 lines (40 loc) · 882 Bytes
/
Menu.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
37
38
39
40
41
42
43
44
45
46
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Menu {
private String title;
private List<String> options;
public Menu(List<String> options) {
this.title = "Menu";
this.options = options;
}
public Menu(String title, List<String> options) {
this.title = title;
this.options = options;
}
public int getSelection() {
int op = 0;
while (op==0){
System.out.println(title+"\n");
int i=1;
for (String option : options) {
System.out.println(i++ + " - " + option);
}
System.out.println("Informe a opcao desejada. ");
Scanner s = new Scanner(System.in);
String str = s.nextLine();
try {
op = Integer.parseInt(str);
}
catch (NumberFormatException e) {
op =0;
}
if (op>=i){
System.out.println("Opcao errada!");
op=0;
}
}
return op;
}
}