Results 1 to 10 of 10
  1. #1
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default Need Help Please

    Hi, i'm currently trying to make a simplish program for calculating soccer results. I'm having trouble with one of my subclasses. The tester class cannot find the methods. Any advice would be appreciated

    Thanks :)
    Last edited by Renegade85; 12-04-2007 at 09:11 PM.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
        public static void main(String[] args)
        {
            Score t1 = new Score("Arsenal", 90);
            Score t2 = new Score("Aston Villa", 78);
    
            t1.calculateScore(t1, t2);
            System.out.println(t1.getTeamName()  + " " +
                               t1.getHomeScore() + "-" +
                               t1.getAwayScore() + " " +
                               t2.getTeamName());
        }

  3. #3
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default

    Thanks hardwired :D

    I'm having another problem now though. Basically i want to have a class that runs when the user program is opened and loads an arraylist with values. Can you do that or will i have to just do it in the main program?
    Last edited by Renegade85; 12-04-2007 at 09:21 PM.

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    public class TeamLoader
    {
        public static void main(String[] args)
        {
            String[] names = {
                "Arsenal", "Aston Villa", "Birmingham", "Blackburn",
                "Bolton", "Chelsea", "Derby", "Everton", "Fulham",
                "Liverpool", "Man City", "Man Utd", "Middlesbrough",
                "Newcastle", "Portsmouth", "Reading", "Sunderland",
                "Tottenham", "West Ham", "Wigan"
            };
            int[] ratings = {
                90, 78, 65, 81, 60, 91, 50, 74, 76, 90,
                89, 91, 82, 77, 83, 59, 57, 81, 74, 54
            };
            TeamInfo[] teams = new TeamInfo[names.length];
            for(int j = 0; j < teams.length; j++) {
                teams[j] = new TeamInfo(names[j], ratings[j]);
            }
            Team team = new Team("a team", 100);
            team.addTeams(teams);
            System.out.println(team);
            System.out.println("bestRated = " + team.getBestRatedTeam());
        }
    }
    
    class Team extends TeamInfo
    {
        ...
        public void addTeams(TeamInfo[] newTeams)
        {
            for(int j = 0; j < newTeams.length; j++)
                teams.add(newTeams[j]);
        }

  5. #5
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default

    Thanks again hardwired :D

    Just one more thing i need to get working and that'll be the program done.

    I can't get one of my cases to work. Will let ya's know how i get on
    Last edited by Renegade85; 12-04-2007 at 09:15 PM.

  6. #6
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default

    Got it going. Just a few minor errors i need to get sorted now
    Last edited by Renegade85; 12-04-2007 at 09:16 PM.

  7. #7
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    I can't get case 1 to work. All the other classes are the same as in my above post except i added the addTeams() method to Team
    The Score class you posted above has some problems.
    Java Code:
    // Methods like this
    protected int setAwayScore()
    {
        return score2;
    }
    // should be implemented like this
    protected void setAwayScore(int score)
    {
        score2 = score;
    }
    As for your last–posted UserProgram class, compiling gives this in the console:
    Java Code:
    C:\jexp>javac scoretesterrx.java
    scoretesterrx.java:55: getRating() in TeamInfo cannot be applied to (java.lang.S
    tring)
                        tempRating=team1.getRating(teamName);
                                        ^
    scoretesterrx.java:61: getRating() in TeamInfo cannot be applied to (java.lang.S
    tring)
                        tempRating=team2.getRating(teamName);
                                        ^
    2 errors
    Score extends TeamInfo and inherits the getRating method from this superclass.
    The TeamInfo getRating method (from post #3) is:
    Java Code:
        public int getRating()
        {
            return rating;
        }
    So you are calling a method that does not exist.

  8. #8
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default

    Ok thanks for pointing them out hardwired. I have to go to work now so will try fix them tomorrow morning. I'll let you know how i get on

  9. #9
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default

    Got most of it sorted now. A few more minor errors and i'm done
    Last edited by Renegade85; 12-04-2007 at 09:17 PM.

  10. #10
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default

    Got it all running now. Thanks for all your help hardwired :D
    Last edited by Renegade85; 12-02-2007 at 09:36 PM.

Posting Permissions

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