I'm trying to create a menu page that allows addition to the array, output of the array and to search by name. I'm struggling with the search part, as it is a multi-dimensional array. How do I search just the names part of each object?
I'm also not sure how to loop this so that they return to the main page after each request, and therefore the array remains updated with any new editions.
package qa.com.task;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import qa.com.task.Person;
public class Runner {
public static void main(String[] args) {
Person pp1 = new Person("Karen", 27, "DevOps Engineer");
Person pp2 = new Person("Jim", 24, "Software Engineer");
// Create array
ArrayList<Person> people = new ArrayList<Person>();
people.add(pp1);
people.add(pp2);
// Search array
Scanner scan = new Scanner(System.in);
System.out.println("---------------------MENU---------------------");
System.out.println("------Create--------Search-------Output All---");
System.out.println("------type c--------type s---------type o-----");
String request = scan.nextLine();
if (request.contains("c")){
//CREATE NEW PERSON
System.out.println("----------Create Request: Enter Name----------");
String newname = scan.nextLine();
System.out.println("-------------------Enter Age-------------------");
Integer newage = scan.nextInt();
scan.nextLine();
System.out.println("-------------------Job Title-------------------");
String newjobtitle = scan.nextLine();
Person ppnew = new Person(newname, newage, newjobtitle);
people.add(ppnew);
System.out.println("-----Updated Array with New Creation Request----");
System.out.println(Arrays.toString(people.toArray()));
}
if (request.contains("s")){
//SEARCH
System.out.println("----------Search Request: Enter Name----------");
String searchname = scan.nextLine();
}
if (request.contains("o")){
//OUTPUT DATABASE
System.out.println("----------------Output Request:----------------");
System.out.println(Arrays.toString(people.toArray()));
}
}}