Need help doing sorts

Reply

Join Date: Apr 2008
Posts: 15
Reputation: dimples09 is an unknown quantity at this point 
Solved Threads: 0
dimples09 dimples09 is offline Offline
Newbie Poster

Need help doing sorts

 
0
  #1
Oct 3rd, 2008
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("------------------------");



}
}
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,444
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Need help doing sorts

 
0
  #2
Oct 3rd, 2008
Well, I guess you weren't paying attention at all in class when sorting was discussed. You haven't even started a skeletal implementation of a single algorithm.

I'd say you have some reading to do first: http://en.wikipedia.org/wiki/Sorting_algorithm
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC