The Artima Developer Community
Sponsored Link

Java Answers Forum
java arraylists

1 reply on 1 page. Most recent reply: Dec 28, 2005 11:50 PM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
java java

Posts: 1
Nickname: java13000
Registered: Dec, 2005

java arraylists Posted: Dec 28, 2005 4:50 AM
Reply to this message Reply
Advertisement
Hi,

I am writting a small program in java for my local club and would like some help please. I am trying to create a 2 person team

I have two arraylists of "track" and "field".

each arraylist for each runner or swimmer contains the details, all as strings:

forename
surname
specialities


After the have been added to their separate arraylist, all i want to do is print to the screen the first "field" competitor with the first "track" competitor.

This leaving me with a list of competitors paired together as a two person team.

Thank you for the help and I look forward to hearing your responses :D


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: java arraylists Posted: Dec 28, 2005 11:50 PM
Reply to this message Reply
Suggestions:

You should create a Runner Bean and a Swimmer Bean:

These are the Objects you will place in the ArrayList

e.g:
//  Could simply be an extension of Person
class Runner extends Person{
   private String foreName;
   private String familyName;
   private String specialities;
   
   public void setForeName(String foreName){
      this.foreName = foreName;
   }
   
   public String getForeName(){
      return this.foreName;
   }
   
   //  repeat this for familyName and specialities
   
   public String toString(){
      return "Runner - Forename: "+this.foreName+"\tFamily Name: "+this.familyName+"Speciality: "+this.specialities+"\n\n";
   }
}


In another class you'll be doing things like:
Runner runner1 = new Runner();
//  Input could be via a database or FileReader
runner.setForeName(Some_Class_That_Takes_In_Strings_On_A_Name_Request);
runner.setFamilName(Inputing_Family_Name);
runner.setSpeciality(some_speciality);
 
//  This is if you are using Java 5
java.util.List<Person> listCompetitors = new ArrayList<Person>();
listCompetitors.add(runner);
//  Iterate through listCompetitors printing each Person
for(Person person: listCompetitors){
   int i = 1;
   System.out.println("Competitor Number "+i+")"+ person.toString());
   i++;
}

Flat View: This topic has 1 reply on 1 page
Topic: JSF <h:selectOneListBox> Previous Topic   Next Topic Topic: need some help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use