Hello all so I was given this Driver class and was told to make classes to get the driver class working properly. For the most part I think im on the right track but then again im not completely sure because I am new to java. I am getting 2 compiling errors because I have not added a add(temp) method. to be honest im not sure what class to put the method into. for now I have it in the Team class but im getting a compiling error. if anyone can give me some insight it will be well appreciated.
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
}
}
my League class
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;
}
}
my Team Class
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
}
}
add()method should be in theLeagueclass:public void add(Team team) { /* ... */ }. Also, tag your question with thejavatag.