ואגב אחרי שאני יוצר קבוצה מסויימת אני לא מצליח להגיע ל-AddTeam ואין לי מושג למה.
אני שפוט יוצר אובייקט של קבוצה:
קוד: בחירת הכל
FootballTeam ft1 = new FootballTeam(10, "Maccabi Tel Aviv");
אחכ אני רושם ft1. ואין לי את AddTeam
זה הקוד שלי: (ה-AddTeam נמצא ב-Class TeamList)
קוד: בחירת הכל
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
namespace test
{
public class IncorrectTeamID : ApplicationException
{
public IncorrectTeamID(string message)
: base(message)
{
}
}
public class Game
{
int HostTeamID;
int GuestTeamID;
int HostGoals;
int GuestGoals;
public Game(int hostTeamId, int guestTeamID, int hostGoals, int guestGoals)
{
this.HostTeamID = hostTeamId;
this.GuestTeamID = guestTeamID;
this.HostGoals = hostGoals;
this.GuestGoals = guestGoals;
}
public int Host_Team_ID
{
get { return this.HostTeamID; }
}
public int Guest_Team_ID
{
get { return this.GuestTeamID; }
}
public int Host_Goals
{
get { return this.HostGoals; }
}
public int Guest_Goals
{
get { return this.GuestGoals; }
}
public override string ToString()
{
return "Host Team ID :" + HostTeamID + "Host Team Goals: " + HostGoals + "Guest Team ID: " + GuestTeamID + "Guest Team Goals: " + GuestGoals;
}
}
public abstract class Team : IComparable
{
int TeamID;
string TeamName;
int gameCount = 0;
Game[] GamesArray = new Game[50];
public Team(int teamID, string teamName)
{
if (teamID < 1 || teamID > 24)
{
throw new IncorrectTeamID("Team ID Should Be between 1 and 24: " + teamID);
}
this.TeamID = teamID;
this.TeamName = teamName;
}
public void AddGame(Game game)
{
GamesArray[gameCount] = game;
gameCount++;
}
public int Team_ID
{
get { return this.TeamID; }
}
public string Team_Name
{
get { return this.TeamName; }
}
public override string ToString()
{
return TeamID + "\t" + TeamName + "\t";
}
public int Score
{
get { return Score; }
}
public int GameCount()
{
return this.gameCount;
}
public int GameCount(Team t2)
{
int count = 0;
for (int i = 0; i < GamesArray.Length; i++)
{
if (t2.TeamID == GamesArray[i].Host_Team_ID || t2.TeamID == GamesArray[i].Guest_Team_ID)
{
count++;
}
}
return count;
}
public int CompareTo(object obj)
{
throw new NotImplementedException();
}
}
public class FootballTeam : Team
{
public FootballTeam(int teamID, string teamName)
: base(teamID, teamName)
{
}
//public int Score
//{
// get
// {
// }
//}
}
public class BasketballTeam : Team
{
public BasketballTeam(int TeamID, string TeamName)
: base(TeamID, TeamName)
{
}
public int Score
{
get
{
return 0;
}
}
}
public class TeamList
{
Team[] AllTeamsArray = new Team[24];
int TeamCount = 0;
public void AddTeam(Team t)
{
AllTeamsArray[TeamCount] = t;
TeamCount++;
}
public bool GetTeam(int teamID, out Team team)
{
team = null;
for (int i = 0; i < AllTeamsArray.Length; i++)
{
if (AllTeamsArray[i].Team_ID == teamID)
{
team = AllTeamsArray[i];
return true;
}
}
return false;
}
}
class Program
{
static void Main(string[] args)
{
//games
#region
Game g1 = new Game(1, 2, 3, 1);
Game g2 = new Game(2, 1, 6, 4);
Game g3 = new Game(1, 3, 0, 4);
Game g4 = new Game(1, 3, 2, 2);
Game g5 = new Game(1, 2, 3, 6);
Game g6 = new Game(2, 1, 0, 0);
Game g7 = new Game(2, 3, 4, 0);
Game g8 = new Game(3, 2, 0, 1);
Game g9 = new Game(2, 3, 0, 0);
Game g10 = new Game(2, 1, 0, 0);
Game g11 = new Game(3, 1, 4, 3);
Game g12 = new Game(2, 3, 3, 1);
Game g13 = new Game(3, 2, 1, 0);
Game g14 = new Game(3, 2, 5, 0);
Game g15 = new Game(2, 3, 2, 3);
#endregion
//teams
#region
FootballTeam ft1 = new FootballTeam(10, "Maccabi Tel Aviv");
FootballTeam ft2 = new FootballTeam(11, "Hapoel Tel Aviv");
FootballTeam ft3 = new FootballTeam(12, "Beitar Jerusalem");
#endregion
//add games
#region
ft1.AddGame(g1);
ft1.AddGame(g2);
ft1.AddGame(g3);
ft1.AddGame(g4);
ft1.AddGame(g5);
ft1.AddGame(g6);
ft1.AddGame(g10);
ft1.AddGame(g11);
ft1.AddGame(g12);
ft1.AddGame(g14);
ft2.AddGame(g1);
ft2.AddGame(g2);
ft2.AddGame(g5);
ft2.AddGame(g6);
ft2.AddGame(g7);
ft2.AddGame(g8);
ft2.AddGame(g9);
ft2.AddGame(g10);
ft2.AddGame(g13);
ft2.AddGame(g14);
ft2.AddGame(g15);
ft3.AddGame(g3);
ft3.AddGame(g4);
ft3.AddGame(g7);
ft3.AddGame(g8);
ft3.AddGame(g9);
ft3.AddGame(g11);
ft3.AddGame(g13);
ft3.AddGame(g15);
#endregion
Console.WriteLine("Team ID\t" + "Team Name" + "\n------------------------");
Console.WriteLine(ft1.ToString());
Console.WriteLine(ft2.ToString());
Console.WriteLine(ft3.ToString());
int a = ft1.GameCount();
int b = ft2.GameCount();
int c = ft3.GameCount();
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
//int d = ft1.GameCount(ft3);
//Console.WriteLine(d);
int e = ft1.Score;
Console.WriteLine(e);
Console.ReadLine();
}
}
}