Created
September 28, 2015 19:45
-
-
Save Deathnerd/ce5b005c429c2b7cd1a5 to your computer and use it in GitHub Desktop.
An example of inline ArrayList declarations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gilleland.george; | |
import com.gilleland.george.utils.Utils; | |
import java.util.ArrayList; | |
public class Main { | |
public static void main(String[] args) { | |
// write your code here | |
Utils.menu(new ArrayList<String>() {{ | |
add("foo"); | |
add("bar"); | |
}}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gilleland.george.utils; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
/** | |
* Created by Wes Gilleland on 9/28/2015. | |
*/ | |
public class Utils { | |
private static Scanner in = new Scanner(System.in); | |
private static String default_prompt = "Enter your choice: "; | |
/** | |
* Display a menu for program navigation with a 0 exit option | |
* @param choices The choices to display | |
*/ | |
public static int menu(ArrayList<String> choices){ | |
int i = 1; | |
for(String choice: choices){ | |
System.out.printf("%d. %s\n", i++, choice); | |
} | |
System.out.println("0. Exit"); | |
System.out.println(Utils.default_prompt); | |
return Utils.in.nextInt(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment