Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MoreExercises.teamworkProject;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = Integer.parseInt(sc.nextLine());
- List<Team> teams = new ArrayList<>();
- List<User> users = new ArrayList<>();
- for (int i = 0; i < n; i++) {
- String input = sc.nextLine();
- String[] tokens = input.split("-");
- User user = new User(tokens[0]);
- Team team = new Team(user, tokens[1]);
- teams.add(team);
- users.add(user);
- team.setUser(user);
- int count = 0;
- for (Team t : teams) {
- if (t.equals(team)) {
- count++;
- // System.out.printf("Team %s has been created by %s!", team.getName(), user.getName());
- if (count == 2) {
- System.out.printf("Team %s was already created!", team.getName());
- teams.remove(team);
- users.remove(user);
- }
- }
- }
- int count2 = 0;
- for (User u : users) {
- if (u.equals(user)) {
- count2++;
- if (count2 == 2) {
- System.out.printf("%s cannot create another team!", user.getName());
- teams.remove(team);
- users.remove(user);
- }
- }
- }
- if (teams.contains(team)) {
- System.out.printf("Team %s has been created by %s!", team.getName(), user.getName());
- System.out.println();
- }
- }
- String command = sc.nextLine();
- while (!command.equals("end of assignment")) {
- String[] tokens = command.split("->");
- User user = new User(tokens[0]);
- Team team = new Team(user, tokens[1]);
- team.setTeamsUsers(users);
- teams.add(team);
- for (Team t : teams) {
- if (!t.getName().equals(team.getName())) {
- System.out.printf("Team %s does not exist!", team.getName());
- } else {
- team.addUser(user);
- }
- }
- for (Team t : teams) {
- if (t.getTeamsUsers().contains(user)) {
- System.out.printf("Member %s cannot join team %s", user, team);
- }
- }
- command = sc.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement