forked from giakinh0823/java-programming-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.java
More file actions
37 lines (34 loc) · 1.01 KB
/
Copy pathMenu.java
File metadata and controls
37 lines (34 loc) · 1.01 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package workshop6;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author giaki
*/
public class Menu {
public static int getChoice(ArrayList<String> options){
int i=1;
for (String option : options) {
System.out.println(i+"-"+option);
i++;
}
System.out.print("Choose 1.." + options.size()+": ");
Scanner scanner = new Scanner(System.in);
return Integer.parseInt(scanner.nextLine());
}
public static int getChoice(Object[] options){
int i=1;
for (Object option : options) {
System.out.println(i+"-"+option.toString());
i++;
}
System.out.print("Choose 1.." + options.length+": ");
Scanner scanner = new Scanner(System.in);
return Integer.parseInt(scanner.nextLine());
}
}