Thank you for taking the time to look at this. I am having some trouble with a project of mine. As of now I have 2 array lists that collect names and ids. I want to link the objects of both lists (the name and id) with each other so that I can perform a insertion sort algorithm later.
Tasks:
1) Ask the user to input names and IDs for team members. Users should alternate inputting names and IDs on separate lines, as shown in the sample run below. As the information is provided, TeamMembers will be added to an ArrayList of TeamMember objects. Remember that names should be stored in title case inside of the TeamMember class.
2)The user should enter the word "STOP" in any combination of lowercase and uppercase letters to stop entering team member information.
3)Sort the ArrayList in increasing order by ID using the insertion sort algorithm. You can choose to use the insertion sort algorithm as you are inserting each new TeamMember object into the array, or you can wait until the entire array is constructed before sorting all of its members at once.
4)After all the names are entered and sorted, print the contents of the ArrayList using ArrayList.toString().
package com.company;
import java.util.*;
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
String inputName;
String inputID;
List<String> fullName = new ArrayList<String>();
List<String> idString = new ArrayList<String>();
while (!(fullName.contains("stop"))) {
Scanner uInput = new Scanner(System.in);
//String checkInput = "test";
System.out.println("Please enter the name: ");
inputName = uInput.nextLine();
fullName.add(inputName.toLowerCase());
// System.out.println("List: " + fullName); //Check what is in the fullName List
// System.out.println("List Size: " + fullName.size()); // Check the size of fullName ArrayList
System.out.println("Please enter the ID: ");
inputID = uInput.nextLine();
idString.add(inputID.toLowerCase());
}
fullName.remove(fullName.size() - 1); //removing the last word, which is always "stop"
idString.remove(idString.size() - 1); //(Same as above)
//insertionSort(fullName);
//insertionSort(idString);
}
HashMap newmap = new HashMap(); //creating hash map
Best, Nate