2017-12-13 8 views
0

こんにちは私はこのDriverクラスを与えられ、クラスを作成してドライバクラスが正しく動作するように指示されました。ほとんどの場合、私は正しい軌道に乗っていると思っていますが、私はJavaを初めて使い慣れているので、再び完全にはわかりません。 add(temp)メソッドを追加していないため、2つのコンパイルエラーが発生しています。正直なところ、どのクラスでメソッドを入れるのかわからない。今のところ私はチームのクラスでそれを持っていますが、私はコンパイルエラーを取得しています。誰かが私にいくつかの洞察を与えることができれば、それはよく評価されるだろう。メソッドとオブジェクトを作成する

public class Driver{ 
public static void main(String args[]) throws Exception{ 
    //All information is stored in input.txt and is being 
    //read in below. 
    Scanner input = new Scanner(new File("input.txt")); 
    //Creates a new League and passes in a String signifying 
    //which league it is. 
    League american = new League("AL"); 
    League national = new League("NL"); 
    for(int i=0; i<15; i++){ 
     //Creates a new team and adds the current team 
     //to the american league. 
     //You can assume there are exactly 15 teams in each league. 
     Team temp = new Team(input.next()); 
     american.add(temp); // compile error 
    } 
    for(int i=0; i<15; i++){ 
     //Creates a new team and adds the current team 
     //to the national league. 
     //You can assume there are exactly 15 teams in each league. 
     Team temp = new Team(input.next()); 
     national.add(temp); // compile error 
    } 
    } 

私のリーグクラス

public class League{ 
private String league; 

public League(String League){ 
    league = League; 
} 

public void setLeagueAmerican(String League){ 
    this.league = League; 
} 

public String getLeagueAmerican(){ 
    return league; 
} 

public void setLeagueNational(String national){ 
    this.league = national; 
} 

public String getLeagueNational(){ 
    return league; 
} 


public void League(String League){ 

    league = League; 

} 
} 

私のチームのクラス

public class Team 
{ 
// instance variables - replace the example below with your own 
private String team; 

/** 
* Constructor for objects of class Team 
*/ 
public Team(String Team) 
{ 
    team = Team; 
} 

public void setTeam(String Team){ 
    this.team = Team; 
} 

public String getTeam(){ 
    return team; 
} 



public String add(League y) 
{ 

    return y;  //compiling error 
} 
} 
+3

は常に '追加()'メソッドは 'にすべきであるとコンパイルエラーを –

+0

投稿しますリーグクラス: 'public void add(チームチーム){/ * ... * /}'また、 'java'タグであなたの質問にタグを付けてください。 –

+0

リーグクラスの –

答えて

1
public String add(League y) 
{ 
    return y;  //compiling error 
} 

この関数は、Stringを返します。パラメータyを渡しています。これはLeagueです。 Leagueと同じものを返すようにしてください。エラーが発生するのはStringです。

どちらかLeagueする戻り値の型を変更、またはyが、意味のある文字列(あるいはy.toString())を返さない

関連する問題