My code to search from ArrayList:
public void searchFromList() {
String color;
System.out.print("Input the color: ");
Scanner scan = new Scanner(System.in);
color = scan.nextLine();
boolean test = false;
for (Fruit fruit: fruits) {
if (fruit.getcolor().equals(color)) {
System.out.println(fruit);
test = true;
}
}
if (!test){
System.out.println();
System.out.println("Sorry there is no " + color + " fruit in list");
}
}
If input is "green", output will be:
01 Pear
03 Watermelon
How do I make the output be a menu like:
[1] 01 Pear
[2] 03 Watermelon
[3] Back to Menu
Thank you! This is not an assignment, please feel free to give advice!