2013-03-08 58 views
-2

我正在使用Java爲2013 NCAA籃球聯賽嘗試創建模擬器。我已經搞混了一些東西在一起,但我開始意識到我不得不硬編碼很多它。籃球比賽預測軟件需要的軟件設計幫助

我想拋出我迄今爲止所做的,看看如果任何人有任何建議,以更好的方式去做。

所以,

我有保存所有的團隊信息,團隊類(姓名,場均得分,排名,平均每場助攻,等...)有一個團隊約30場。但Team對象也包含許多Player對象。 Player對象也有大約25個字段。

我計劃有一個驅動程序類添加這些球隊中,但64支球隊看起來我會花幾個小時去手動添加64支球隊每個具有10名以上玩家噸領域。有沒有更好的方式去做這件事?也許讓我的程序從我創建的Excel表格中提取信息?

另外我有一個支架類,帶有64支球隊,並使用團隊信息構建支架的方式NCAA支架會。

最後我不知道如何把它放在一個簡單的GUI支架上,它將顯示支架。

還有很多漏洞,我只是需要一些關於最佳前進方向的建議,謝謝。

此外,由於那裏有一個更好的方式來做到這一點,這是我的支架類到目前爲止的樣子。我還沒有編碼如何組織它,我只是把64個團隊放在一個數組中。

public class Bracket 
{ 
    private Team team1, team2, team3, team4, team5, team6, 
       team7, team8, team9, team10, team11, team12, 
       team13, team14, team15, team16, team17, team18, 
       team19, team20, team21, team22, team23, team24, 
       team25, team26, team27, team28, team29, team30, 
       team31, team32, team33, team34, team35, team36, 
       team37, team38, team39, team40, team41, team42, 
       team43, team44, team45, team46, team47, team48, 
       team49, team50, team51, team52, team53, team54, 
       team55, team56, team57, team58, team59, team60, 
       team61, team62, team63, team64; 

    //midwest, west, south, east 
    Bracket(Team team1, Team team2, Team team3, Team team4, Team team5, 
      Team team6, Team team7, Team team8, Team team9, Team team10, 
      Team team11, Team team12, Team team13, Team team14, Team team15, 
      Team team16, Team team17, Team team18, Team team19, Team team20, 
      Team team21, Team team22, Team team23, Team team24, Team team25, 
      Team team26, Team team27, Team team28, Team team29, Team team30, 
      Team team31, Team team32, Team team33, Team team34, Team team35, 
      Team team36, Team team37, Team team38, Team team39, Team team40, 
      Team team41, Team team42, Team team43, Team team44, Team team45, 
      Team team46, Team team47, Team team48, Team team49, Team team50, 
      Team team51, Team team52, Team team53, Team team54, Team team55, 
      Team team56, Team team57, Team team58, Team team59, Team team60, 
      Team team61, Team team62, Team team63, Team team64) 
      { 
       team1 = this.team1; 
       team2 = this.team2; 
       team3 = this.team3; 
       team4 = this.team4; 
       team5 = this.team5; 
       team6 = this.team6; 
       team7 = this.team7; 
       team8 = this.team8; 

       team9 = this.team9; 
       team10 = this.team10; 
       team11 = this.team11; 
       team12 = this.team12; 
       team13 = this.team13; 
       team14 = this.team14; 
       team15 = this.team15; 
       team16 = this.team16; 

       team17 = this.team17; 
       team18 = this.team18; 
       team19 = this.team19; 
       team20 = this.team20; 
       team21 = this.team21; 
       team22 = this.team22; 
       team23 = this.team23; 
       team24 = this.team24; 

       team25 = this.team25; 
       team26 = this.team26; 
       team27 = this.team27; 
       team28 = this.team28; 
       team29 = this.team29; 
       team30 = this.team30; 
       team31 = this.team31; 
       team32 = this.team32; 

       team33 = this.team33; 
       team34 = this.team34; 
       team35 = this.team35; 
       team36 = this.team36; 
       team37 = this.team37; 
       team38 = this.team38; 
       team39 = this.team39; 
       team40 = this.team40; 

       team41 = this.team41; 
       team42 = this.team42; 
       team43 = this.team43; 
       team44 = this.team44; 
       team45 = this.team45; 
       team46 = this.team46; 
       team47 = this.team47; 
       team48 = this.team48; 

       team49 = this.team49; 
       team50 = this.team50; 
       team51 = this.team51; 
       team52 = this.team52; 
       team53 = this.team53; 
       team54 = this.team54; 
       team55 = this.team55; 
       team56 = this.team56; 

       team57 = this.team57; 
       team58 = this.team58; 
       team59 = this.team59; 
       team60 = this.team60; 
       team61 = this.team61; 
       team62 = this.team62; 
       team63 = this.team63; 
       team64 = this.team64; 
      } 

    public Team[] buildBracket(Team team1, Team team2, Team team3, Team team4, Team team5, 
      Team team6, Team team7, Team team8, Team team9, Team team10, 
      Team team11, Team team12, Team team13, Team team14, Team team15, 
      Team team16, Team team17, Team team18, Team team19, Team team20, 
      Team team21, Team team22, Team team23, Team team24, Team team25, 
      Team team26, Team team27, Team team28, Team team29, Team team30, 
      Team team31, Team team32, Team team33, Team team34, Team team35, 
      Team team36, Team team37, Team team38, Team team39, Team team40, 
      Team team41, Team team42, Team team43, Team team44, Team team45, 
      Team team46, Team team47, Team team48, Team team49, Team team50, 
      Team team51, Team team52, Team team53, Team team54, Team team55, 
      Team team56, Team team57, Team team58, Team team59, Team team60, 
      Team team61, Team team62, Team team63, Team team64) 
    { 
     Team[] bracketArray; 
     bracketArray = new Team[64]; 

     bracketArray[0] = team1; 
     bracketArray[1] = team2; 
     bracketArray[2] = team3; 
     bracketArray[3] = team4; 
     bracketArray[4] = team5; 
     bracketArray[5] = team6; 
     bracketArray[6] = team7; 
     bracketArray[7] = team8; 

     bracketArray[8] = team9; 
     bracketArray[9] = team10; 
     bracketArray[10] = team11; 
     bracketArray[11] = team12; 
     bracketArray[12] = team13; 
     bracketArray[13] = team14; 
     bracketArray[14] = team15; 
     bracketArray[15] = team16; 

     bracketArray[16] = team17; 
     bracketArray[17] = team18; 
     bracketArray[18] = team19; 
     bracketArray[19] = team20; 
     bracketArray[20] = team21; 
     bracketArray[21] = team22; 
     bracketArray[22] = team23; 
     bracketArray[23] = team24; 

     bracketArray[24] = team25; 
     bracketArray[25] = team26; 
     bracketArray[26] = team27; 
     bracketArray[27] = team28; 
     bracketArray[28] = team29; 
     bracketArray[29] = team30; 
     bracketArray[30] = team31; 
     bracketArray[31] = team32; 

     bracketArray[32] = team33; 
     bracketArray[33] = team34; 
     bracketArray[34] = team35; 
     bracketArray[35] = team36; 
     bracketArray[36] = team37; 
     bracketArray[37] = team38; 
     bracketArray[38] = team39; 
     bracketArray[39] = team40; 

     bracketArray[40] = team41; 
     bracketArray[41] = team42; 
     bracketArray[42] = team43; 
     bracketArray[43] = team44; 
     bracketArray[44] = team45; 
     bracketArray[45] = team46; 
     bracketArray[46] = team47; 
     bracketArray[47] = team48; 

     bracketArray[48] = team49; 
     bracketArray[49] = team50; 
     bracketArray[50] = team51; 
     bracketArray[51] = team52; 
     bracketArray[52] = team53; 
     bracketArray[53] = team54; 
     bracketArray[54] = team55; 
     bracketArray[55] = team56; 

     bracketArray[56] = team57; 
     bracketArray[57] = team58; 
     bracketArray[58] = team59; 
     bracketArray[59] = team60; 
     bracketArray[60] = team61; 
     bracketArray[61] = team62; 
     bracketArray[62] = team63; 
     bracketArray[63] = team64; 

     return bracketArray; 
    } 
} 
+0

你當然意識到,NCAA錦標賽現在有68支球隊。 – duffymo 2013-03-08 23:39:53

+0

是的,但我不在乎包含初步比賽。我知道運動感謝.. – 2013-03-09 02:36:16

回答

2

這個問題非常廣泛,但我可以提供一些設計技巧。

獨立您從您的算法數據

不要硬編碼所有的東西在裏面;而是將數據存儲在數據庫,電子表格或CSV中,或從互聯網上隨時獲取。然後明年,您可以在不觸及代碼行或編譯任何內容的情況下對新數據運行預測器。

通行證列表作爲參數

Bracket(List<Team> teams) { 
    if (teams == null || teams.size() != 64) { 
     throw IllegalArgumentException("Oops! Need 64 teams!"); 
    } 

    // ... 
} 

也許從下往上

解決每場比賽的設計肯定是你想要的,但這個方案的真正價值將決定一個兩個團隊對象之間的匹配。不要擔心如何確定「支架」是什麼,或者視圖的外觀如何;而是從小處開始,並從那裏建設。

public class Game { 
    public Game(Team team1, Team team2) { 
     // ... 
    } 
} 

public class Predictor { 
    public Predictor(/* Some values you can tweak*/) { 
     // ... 
    } 

    public Team predict(Game game) { 
     // ... 
    } 
} 
+0

這真的有幫助!我知道這個問題很廣泛,得到了「譴責」。我是新來的使用這樣的論壇,但這是我一直在尋找。 – 2013-03-12 22:33:54