This is the main of my program all errors have been solved now I need help sorting my array list with a selection, bubble and insertion sort to print out in
alphabetic order using the name as key
numeric order using the income as key
order of nationality in alphabetic order
Each array must have its own class. Im clueless on how to do this and been sitting at the computer feeling stupid please help!!!!
// ***************************************************************************************
// Demographics.java Programmed by : [[Alana R. Lewis]]
//
//
//
//Implement a set of classes that define various types of demographic information
//about a set of people, such as age, nationality, occupation, income and so on.
//You will find appropriate classes defined below and illustrated in the UML diagrams.
// ****************************************************************************************
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;
import java.io.*;
public class Demographics
{
public static void main(String[] args)throws IOException
{
System.out.println("I did not receive any assistance from anyone other than Mr. Willis or an assigned tutor.\n");
// create a fileScan Scanner for a file, StudentNames.txt
Scanner fileScan = new Scanner(new File("Demographics.txt"));
ArrayList people = new ArrayList();
// check whether the fileScan has the next item (i.e., next line)
while (fileScan.hasNext()) // // Read until file is exhausted
{
// create a String Tokenizer for a line
StringTokenizer st = new StringTokenizer( fileScan.nextLine());
// read name from tokenizer
String name = st.nextToken();
// read income from tokenizer
String ageString = st.nextToken();
// convert gpa into double
int age = Integer.parseInt( ageString );
// read gender from tokenizer
String gString = st.nextToken();
// read gender from tokenizer
Gender_Type gender = Gender_Type.valueOf( gString );
// read nationality from tokenizer
String nString = st.nextToken();
// read nationality from tokenizer
Nationality_Type nationality = Nationality_Type.valueOf( nString );
// read occupation from tokenizer
String oString = st.nextToken();
// read occupation from tokenizer
Occupation_Type occupation = Occupation_Type.valueOf( oString );
// read income from tokenizer
String incomeString = st.nextToken();
// convert gpa into double
double income = Double.parseDouble( incomeString );
//new person and insert into arraylist
Person person = new Person();
// do the sets
// print the person
person.setName(name);
person.setAge(age);
person.setGender(gender);
person.setNationality(nationality);
person.setOccupation(occupation);
person.setIncome(income);
people.add(person);
}
//print arraylist
System.out.println(people);
//do the sorts
//Print out List for Alphabetic Order(using the name as the key)
System.out.println("\nAlpabetic Order List");
System.out.println("----------------------");
//Print out list in numeric order (using income as key)
System.out.println("\nNumeric Order List");
System.out.println("--------------------");
//Print out list in order of nationality(Alphabetic Order)
System.out.println("\nNationality Order List");
System.out.println("------------------------");
}
}