Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

accessing attributes and methods in ArrayList of objects??

finniefinnie Member Posts: 1
Hi

I need help on a small database, with video clips and corresponding competitors, i'll need to be access both individual clips by index, and the clips of a competitor for sorting etc.

So far i can add Competitor objects to an ArrayList within my main client class, but i'm having trouble accessing their attributes or using methods of the Competitor class

This is my Competitor.java: (also has standard .set .get methods for each attribute)
[code]
public class Competitor {

private String surname;
private String givenname;
private ArrayList ClipList = new ArrayList();

// Competitor object constructor
public Competitor(String surname, String givenname, ArrayList ClipList) {
this.surname = surname;
this.givenname = givenname;
this.ClipList = ClipList;
}
[/code]
Heres a method out of my main client class (which contains ClipList and CompetitorList) The end goal is to have a CompetitorList, and each Competitor will have an ArrayList of Clips he/she owns. There will also be a main ClipList of the same Clips so i can access any Clip by its index. does this sound right?
This method has both ClipList and CompetitorList passed to it from the main method, it calls other methods to read input and add a new Competitor to CompetitorList. Is this the best/right way to alter the lists?
[code]
public static void clipAddOption(ArrayList ClipList, ArrayList CompetitorList) {

System.out.println("clipAddOption stub");

boolean addCompetitor = question("Do you need to add a new competitor?");

if (addCompetitor) {

CompetitorList.add(readCompetitor());
[/code]
This seems to work fine, but how on earth to i access the elements of CompetitorList. Do i have modify/access the ArrayLists only from the main method?
I want to be able to call the Competitor.getSurname and Competitor.getGivenname of CompetitorList[i]

Any help will be greatly appreciated! i've been stuck for a while!

Thanks!


Comments

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _ || http://forcoder.org || free ebooks and video tutorials about \ Java, C#, R, Assembly, C++, Perl, Visual Basic, JavaScript, Ruby, Delphi, PL/SQL, PHP, Visual Basic .NET, Swift, Python, C, Objective-C, Go, Scratch, MATLAB Crystal, Lisp, Prolog, Rust, Lua, Erlang, F#, Awk, Clojure, LabVIEW, FoxPro, Ada, Logo, Hack, Fortran, ABAP, Julia, Dart, Bash, SAS, Scheme, Alice, Apex, Scala, Transact-SQL, Kotlin, COBOL, VBScript, ML, D \ ___________

Sign In or Register to comment.