Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am coding a soccer simulation game with group stages.. i have done the team class so far and it is running well. now i need help with the group class where i have to use arrays. It contains the following methods:

addTeam() which adds teams to the team array

matchPlayed() that accepts details of the game and updates the details of the teams

orderedladder() which lists the teams according to their points

and the standings() method which shows the team standings.

How wouil i go about with such a class?
Posted
Comments
#realJSOP 8-May-10 10:54am    
Is this a homework assignment?
Sandeep Mewara 8-May-10 10:57am    
It does look like a homework assignment! ... defned methods to start and move on... TRY yourself first!

Could you please be more specific ? Which problems are you having ? Where are you stuck exactly ?

By looking at the code you posted, there are several issues with it:
- If you have an array of teams, calling this variable "name" is very strange, you could simply go for something like "teams".
- Hardcoding the size of the team array to 4 is very limiting. You could use a LinkedList instead, this way your array can increase depending on the needs (you are using java right ?).
- In the constructor with arguments, what is the purpose of the second argument (int[] name) ?
- The method teamAdd is wrong: you expect a boolean and you return a string. Furthermore you don't add the team to the array of teams but simply return it.
 
Share this answer
 
v2
Fist thing, did you at least try to understand the points I suggested in my previous reply ?

I need to wite a constructor to accept a value for the group name and initialise the team array with space for 4 Team objects.

So, why are you passing an array of integers (name) and the count arguments ? They don't have any meaning or puprose.

A method called addTeam(…) is required to add a team to the array. This
method should be passed a Team object to insert. the Group class is
responsible for keeping track of how many Team objects are in the teams array, to ensure that existing teams are not accidentally replaced.


Well, for now your function doesn't do anything. Hint: you should use the count member variable to know how many teams are already in the array. BTW, will you need to remove teams from the array at some point ? If yes, then you need to check if your array contains null pointers, which means this is an empty slot (and don't dorget to set a slot to null when you remove a team).

A method called getOrderedLadder(…) that can return a String, listing the
teams in the group, in order of number of points scored. I need to iterate through the array of team objects, comparing the match points that each team has.
The last method called getStandings(…) will perform the same actions
as the method above, but will only return the top two teams, for the “final standings”
These are the methods i need help with as you can see i could not begin them in my code.


For these, you should already start doing something on your own. We are here to help you, not do your homework for you.
 
Share this answer
 
Hi,

Sounds like a nice project!

You will get more answers here if you have a go at creating the class and then come back here with a specific problem or question. :thumbsup: :)
 
Share this answer
 
This is my attempt at the class bt i am already having some problems if u can please help.

C#
public class Group
{
    // instance variables
    private String groupName;
    private Team[]name;
    private int count;
    /**
     * Constructor for objects of class Group
     */
    public Group()
    {
    }
    //methods
    public Group (String theGroupName,int [ ] name, int count)
    {
        groupName = theGroupName;
        name = new Team[4] ;
        count = 0;
    }
    public String getGroupname()
    {
        return groupName;
    }

    public int getTeamsize()
    {
        return name.length;
    }
    public void setGroupname()
    {
        groupName = thegroupName;
    }
    public void teamAdd(Team name)
    {
        boolean teamAdded = false;
         for (int count=0; count <4; count ++)
         {
             return name;
         }
    }
}
 
Share this answer
 
v2
I need to wite a constructor to accept a value for the group name and initialise the team array with space for 4 Team objects.

A method called addTeam(…) is required to add a team to the array. This
method should be passed a Team object to insert. the Group class is
responsible for keeping track of how many Team objects are in the teams array, to ensure that existing teams are not accidentally replaced.

A method called getOrderedLadder(…) that can return a String, listing the
teams in the group, in order of number of points scored. I need to iterate through the array of team objects, comparing the match points that each team has.

The last method called getStandings(…) will perform the same actions
as the method above, but will only return the top two teams, for the “final standings”

These are the methods i need help with as you can see i could not begin them in my code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900