Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

2 Visitor Messages

  1. View Conversation
    I would then create a method to compare with each type (by gender, by year, and by last name). In order to compare objects more effectively, I would send these comparing objects Person objects:
    	public int compareGender(Person p)
    	{
    		String tempGen = p.gender;
    		return gender.compareTo(tempGen);
    	}
     
    	public int compareYear(Person p)
    	{
    		String tempDate = p.date;
    		String[] tDateSplit = tempDate.split("/");
    		int tempYear = Integer.parseInt(tDateSplit[2]);
    		String[] dateSplit = date.split("/");
    		int year = Integer.parseInt(dateSplit[2]);
    		return year-tempYear;
    	}
     
    	public int compareLastName(Person p)
    	{
    		String tempLN = p.lastName;
    		return lastName.compareTo(tempLN);
    	}

    See if you can figure out how to implement this to compare the objects and resort the arraylist.

    I hope this helps. It is quite simple to figure this sort of thing out. You just have to work through the problem one step at a time and try to tackle each issue individually.
  2. View Conversation
    Well, if there were no limitations, I would create an object (Person Object perhaps). This object would take a First Name, a Last Name, a Gender, a Date, and an Eye Color:
    public class Person
    {
    	String firstName,lastName,gender,date,eyeColor;	
     
    	public Person(String fName,String lName,String gen,String dat,String eColor)
    	{
    		firstName = fName;
    		lastName = lName;
    		gender = gen;
    		date = dat;
    		eyeColor = eColor;
    	}
    }
Showing Visitor Messages 1 to 2 of 2
About alisa

Basic Information

Statistics


Total Posts
Total Posts
0
Posts Per Day
0
Visitor Messages
Total Messages
2
Most Recent Message
November 7th, 2010 10:43 AM
Total Thanks
Total Thanks
0
  • Thanked 0 Times in 0 Posts
General Information
Last Activity
October 30th, 2010 01:10 AM
Join Date
October 27th, 2010