Results 1 to 2 of 2
  1. #1
    Shorinhio is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default Help with Objects!

    I need to make a Data object for each team in a league. I started by making an array of the objects, but then I could only access the objects by the array index which caused me all kinds of inheritance problems.

    My question is, is there a way of creating objects with the team names?

    For example, say I have an array of strings teamNames[20] containing all the teams in the Premiership, can I create objects named with these team names without doing it manually?

    So, if goalsScored is an attribute of the Data object, and getGoalsScored() is a method, I want to be able to get the number of goals scored with Liverpool.getGoalsScored();

    And then, ideally: (teamString).getGoalsScored();

    Is this possible?

    Any suggestions welcome. Thanks!

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Rep Power


    Why don't you create a Team class like this:

    Java Code:
    class Team {
       String name;
       public void String getName();
    Create your teams array like this:

    Java Code:
    Team[20] teams;
    and then search for the team by checking names of them in a for loop.

    That is the logical method of doing this. Why do you need your implementation?

Similar Threads

  1. Color objects
    By CyberFrog in forum New To Java
    Replies: 4
    Last Post: 04-01-2008, 12:41 AM
  2. Getting objects from a list
    By markyoung1984 in forum New To Java
    Replies: 4
    Last Post: 03-13-2008, 10:45 PM
  3. Objects and Classes
    By Aleve in forum New To Java
    Replies: 8
    Last Post: 12-31-2007, 08:05 AM
  4. how can objects themselves be copied???
    By ishakteyran in forum New To Java
    Replies: 1
    Last Post: 12-29-2007, 10:04 AM
  5. JSP implicit objects
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts