用户输入问题

时间:2016-11-02 22:40:59

标签: java eclipse

我需要一种方法来允许用户输入团队名称和团队成员名称。 我尝试使用扫描仪,但由于我对java的经验不足,因此无法工作。 我只是想让用户输入四个团队成员的团队名称和名称。我把这些变量公之于众,但我不知道如何将数据输入它们,因为它们属于单独的类。

这是代码

主要课程        import java.util.Scanner; 公共课主要{

public static void main(String[] args) {
    Competition comp1 = new Competition("First competition", "IUS team1", "IUS team2" ,2014 );
    Competition comp2 = new Competition("Second competition" , "IUS team3", "IUS team4", 2016);
    Scanner jin = new Scanner(System.in);
    Team teamObject1 = new Team(String Team_name);
    String Team_name = teamObject1.jin.nextLine();

    //Team team1 = new Team("IUS team1", "Adin", "Merzuk", "Segmedina", "Iman", comp1, comp2); 
    Team team2 = new Team(team1); 


    System.out.println(team1);


}

   }

团队课

   public class Team {

public String Team_name; 
public String name1; 
public String name2; 
public String name3; 
public String name4; 
private Competition competition1; 
private Competition competition2; 

public Team(String Team_name, String name1, String name2, String name3, String name4, Competition comp1, Competition comp2){

    this.Team_name = Team_name; 
    this.name1 = name1; 
    this.name2 = name2; 
    this.name3 = name3; 
    this.name3 = name3; 
    this.name4 = name4; 
    competition1 = new Competition(comp1); 
    competition2 = new Competition(comp2); 

    }

    public Team(Team original){
        Team_name = original.Team_name;
        name1 = original.name1; 
        name2 = original.name2; 
        name3 = original.name3; 
        name4 = original.name4; 
        competition1 = original.competition1;
        competition2 = original.competition2;
    }

    public void setTeam_name(String Team_name){ 
        this.Team_name = Team_name; 
    }

    public void setNames(String name1, String name2, String name3, String name4){
        this.name1 = name1; 
        this.name2 = name2; 
        this.name3 = name3; 
        this.name4 = name4;
    }

    public String getTeam_name(){ 
        return Team_name; 
    }
    public String getName1(){ 
        return name1; 
    }
    public String getName2(){ 
        return name2; 
    }
    public String getName3(){ 
        return name3; 
    }
    public String getName4(){ 
        return name4; 
    }

    public String toString(){ 
        return("Team name: " + getTeam_name() + "\nMember1: " + getName1() +"\nMember2: " + getName2() + "\nMember3; "  + getName3()+"\nMember4: " + getName4() +"\n" +  competition1+ "\n"+ competition2  );
    }
   }

比赛课

   public class Competition {

private String nameCompetition; 
private String Winning_team; 
private String runner_up; 

private int Year_Competition; 


public Competition(){ 
    nameCompetition = "Not set"; 
    Winning_team = "Not set"; 
    runner_up = "Not set"; 
    Year_Competition = 0; 
}

public Competition(String nameCompetition, String Winnig_team, String runner_up, int Year_Competition ){

    this.nameCompetition = nameCompetition; 
    this.Winning_team = Winnig_team; 
    this.runner_up = runner_up;
    this.Year_Competition = Year_Competition;

}

public Competition(Competition comp1){ 
    nameCompetition = comp1.nameCompetition;
    Winning_team = comp1.Winning_team; 
    runner_up = comp1.runner_up;
    Year_Competition = comp1.Year_Competition;
}

public void setNameCompetition(String nameCompetition){ 
    this.nameCompetition = nameCompetition;
}

public void setWinningTeam(String Winning_team){ 
    this.Winning_team = Winning_team; 
}

public void setRunnerUp(String runner_up){ 
    this.runner_up = runner_up; 
}

public void setYear(int year_competition){ 
    this.Year_Competition = year_competition; 
}

public String getNameCompetition(){ 
    return nameCompetition; 
}

public String getWinningTeam(){ 
    return Winning_team; 
}
public String getRunnerUp(){ 
    return runner_up; 

}
public int getYear(){ 
    return Year_Competition; 
}

public String toString(){ 
    return("Competition name: " + getNameCompetition() + " Winners: " + getWinningTeam() + " runner up: " + getRunnerUp() + " Year: " + getYear());
}



   }

1 个答案:

答案 0 :(得分:0)

map.keySet().forEach(key -> System.out.println(key + "->" + result.get(key)));