I am making a program and I need to sort this list of first and last names for a seating chart making method on an airplane. It is a 2 dimensional array the first column has the first name, and the second column has the last name of the corresponding person in the first column. I need to sort this in alphabetical order by last name, first name but I cannot figure out how to sort the last name and then keep the corresponding last name.
This is my Code:
package assignment_6_1;
import java.util.Scanner;
import java.util.Arrays;
public class Assignment_6_1 {
public static void main(String[] args) {
//Create a Scanner
Scanner input = new Scanner(System.in);
//Create int & string []
String[][]firstAndLastNames = new String[36][2];
int[]heightOfPerson = new int[36];
String[][]seatingChartDiagram = new String[9][4];
int[][]seatRequest = new int [36][2];
//Gather list of names and heights
for(int i=0; i<heightOfPerson.length; i++)
{
//Get first name
System.out.println("Enter Your First Name: ");
firstAndLastNames[i][0] = input.next();
//Get last name
System.out.println("Enter Your Last Name: ");
firstAndLastNames[i][1] = input.next();
//Get height in inches
System.out.println("Enter your height (Iches) : ");
heightOfPerson[i] = input.nextInt();
//Is there a seat request or not
System.out.println("Do you want to request a seat ?");
String ifSeatRequest = input.next();
//Get seat request
if(ifSeatRequest.equals("Yes") || ifSeatRequest.equals("yes"))
{
System.out.println("Enter the seat row you want: ");
seatRequest[i][0] = input.nextInt();
System.out.println("Enter the seat number you want in that row: ");
seatRequest[i][1] = input.nextInt();
}
else
{
//set the request colum for that person to 0 for no request
seatRequest[i][0] = 0;
seatRequest[i][1] = 0;
}
//Prints passenger manifest when list is full
if(firstAndLastNames[35][1] != null){
System.out.println("All Seats are Filled");
break;}
}
String[]firstNameSort = new String[36];
//put the first names into another array to sort
for(int j=0; j<heightOfPerson.length; j++)
{
firstNameSort[j] = firstAndLastNames[j][1];
}
//Alphabetize first name list
Arrays.sort(firstNameSort);
String[][]firstNameAlphLast = new String[36][2];
String[][]nameAlph = new String[36][2];
}
}
In order: It takes in user input for 36 names, heights, and if the person wants to make a seating request. I made it copy the array 2 another array, and then I alphabetized the last names. Now i can't figure out how to get the corresponding first names for the alphabetized last names.
Personobject with three properties (lastName,firstNameandheight) ?