2017-12-13 8 views
0

안녕하세요.이 드라이버 클래스를 받았고 드라이버 클래스가 제대로 작동하도록 클래스를 만들라고했습니다. 나는 자바에 익숙하지 않기 때문에 대부분의 경우 나는 옳은 길에있는 메신저하지만 다시는 완전히 확신 할 수 없다고 생각합니다. 추가 (임시) 메서드를 추가하지 않았기 때문에 컴파일 오류가 두 번 발생합니다. 솔직히 말해서 어떤 클래스가 메소드를 넣을 지 모르겠다. 지금은 Team 클래스에서 컴파일 오류가 발생했습니다. 누구라도 나에게 통찰력을 줄 수 있다면 잘 이해할 수있을 것이다.메서드 및 객체 만들기

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)을 전달 중입니다. 그런 다음 오류가 발생하는 String 인 것처럼 매우 동일한 League을 반환하려고 시도합니다.

중 하나 League로 반환 형식을 변경하거나 y를 반환하지 않지만 의미있는 문자열 (또는 y.toString()는)