I am making a simple sports simulator. In the beginning you must enter both teams playing in the format (CityName TeamName e.g. Chicago Bulls). I am using two methods to get the name of the city and the name of the team from that initial name so I can call them in separate places for a more natural looking output.
public String getLocation(String teamName){
String location = this.name.substring(0, this.name.indexOf(" "));
return location;
}
public String getFirstName(String teamName){
String name = this.name.substring(this.name.indexOf(" "));
return name;
}
The first method for getting the location works fine. The second one for getting the team name returns null every time. I can't figure out what I've done different in the two as to why I get different results.
EDIT:
Here is the line that is implementing these methods:
System.out.println("The " + TeamX.getFirtName(TeamX.getName()) + " are visting from " + TeamX.getLocation(TeamX.getName()) + " to play the " + TeamY.getFirtName(TeamY.getName()) + " in " + TeamY.getLocation(TeamY.getName()) );
And the output for it when "NYC Jets" and "Arizona Cardinals" has been:
The null are visting from NYC to play the null in Arizona
teamNameand how does it relate tothis.name? Also, it seems highly unlike that you'll be gettingnullfrom either method; do you by any chance mean an empty string ("")?String teamNameto the methods, but then doingname.substring(this.name)? Should the method operate on the parameter?