Click here to Skip to main content
14,920,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I cant printout my country. how to make the country can be read?

What I have tried:

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();

   }
}



Output:
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]
Posted
Updated 27-Oct-20 6:55am

1 solution

There is a bracket missing in your code. Instead of
Python
System.out.println("Team Name : " + team.getTeamName()+ "Team Country : " + team.getTeamCountry);
try
Python
System.out.println("Team Name : " + team.getTeamName()+ "Team Country : " + team.getTeamCountry();
   
v2
Comments
Richard MacCutchan 27-Oct-20 13:21pm
   
Final close parenthesis missing. :(
CHill60 28-Oct-20 6:29am
   
There is a certain irony in me pointing out a missing parenthesis just to miss another one out myself :sigh:
I won't update the solution to avoid reviving the question - hopefully these comments will be enough for the OP and any others

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900