Loke Brian Ответов: 1

Мой вывод кодирования javascript застрял


Я не могу распечатать свою страну. как сделать так, чтобы страну можно было читать?

Что я уже пробовал:

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;


public class Game {
    HashMap<String ,Team> teams = new LinkedHashMap<String ,Team>();


   public void addTeam(String teamName,String teamCountry) {
      Team team =  new Team(teamName,teamCountry) ;
      teams.put(teamName ,team);
   }

   public void addPlayer(String teamName,String name,int score ) {
       Player player = new Player(name,score);
       Team team = teams.get(teamName) ;
       team.addPlayer(player);
   }

   public void print(){
       for(Map.Entry<String , Team> entry : teams.entrySet() ) {
           Team team = entry.getValue();
           System.out.println("Team Name : " + team.getTeamName()+ "Team Country : " + team.getTeamCountry);
           System.out.println("Players : " + team.getPlayers().toString());
       }
   }

   public static void main (String args[]) throws Exception{

       Game game = new Game();

       game.addTeam("team1","Russia");
       game.addTeam("team2","Malaysia");
       game.addTeam("team3","Malaysia");
       game.addTeam("team4","Malaysia");
       game.addTeam("team5","Malaysia");
       game.addTeam("team6","Malaysia");
       game.addTeam("team7","Malaysia");

       game.addPlayer("team1","name1",20);
       game.addPlayer("team1","name2",20);
       game.addPlayer("team2","name3",30);
       game.addPlayer("team2","name4",40);
       game.addPlayer("team3","name5",30);
       game.addPlayer("team3","name6",40);
       game.addPlayer("team4","name7",30);
       game.addPlayer("team4","name8",40);
       game.addPlayer("team5","name9",30);
       game.addPlayer("team5","name10",40);
       game.addPlayer("team6","name11",30);
       game.addPlayer("team6","name12",40);
       game.addPlayer("team7","name13",30);
       game.addPlayer("team7","name14",40);

       game.print();

   }
}



Выход:
Team Name : team1Team Country : null
Players : [name1  20, name2  20]
Team Name : team2Team Country : null
Players : [name3  30, name4  40]
Team Name : team3Team Country : null
Players : [name5  30, name6  40]
Team Name : team4Team Country : null
Players : [name7  30, name8  40]
Team Name : team5Team Country : null
Players : [name9  30, name10  40]
Team Name : team6Team Country : null
Players : [name11  30, name12  40]
Team Name : team7Team Country : null
Players : [name13  30, name14  40]

1 Ответов

Рейтинг:
1

CHill60

В вашем коде отсутствует скобка. Вместо

System.out.println("Team Name : " + team.getTeamName()+ "Team Country : " + team.getTeamCountry);
пробовать
System.out.println("Team Name : " + team.getTeamName()+ "Team Country : " + team.getTeamCountry();


Richard MacCutchan

Последняя закрывающая скобка отсутствует. :(

CHill60

Есть определенная ирония в том, что я указываю на отсутствующую скобку только для того, чтобы пропустить еще одну :вздох:
Я не буду обновлять решение, чтобы избежать возрождения вопроса - надеюсь, этих комментариев будет достаточно для OP и любых других