Професионална програма
Loading...
+ Нов въпрос
Axiomatik avatar Axiomatik 791 Точки

For the tokens = input.split(" -> ") command when a given side doesn't exist, always check whether the target user doesn't exist if so move the user from the old group to the new one:

Your implementation:

                if (!contains(forceBook, forceUser)) {
                    if (!forceBook.containsKey(forceSide)) {
                        forceBook.put(forceSide, new ArrayList<>());
                    }
                    forceBook.get(forceSide).add(forceUser);
                    System.out.printf("%s joins the %s side!%n", forceUser, forceSide);

Implentation that checks whether user is present when target side does not yet exist:

              tokens = input.split(" -> ");
                forceUser = tokens[0];
                forceSide = tokens[1];
                for (Map.Entry<String, List<String>> current : sides.entrySet()) {
                    if (current.getValue().contains(forceUser)) {
                        sides.get(current.getKey()).remove(forceUser);
                        break;
                    }
                }
                if (!sides.containsKey(forceSide)){
                    sides.putIfAbsent(forceSide, new ArrayList<>());
                }
                sides.get(forceSide).add(forceUser);
                System.out.printf("%s joins the %s side!%n", forceUser, forceSide);

 

 

0
Petya.marinova avatar Petya.marinova 3 Точки

Again I have 90 / 100

:(

https://pastebin.com/6V0dTCGy

0
St.tsoneva avatar St.tsoneva 13 Точки

Колежке,

виж този вход:

Dark | Pesho
Pesho -> Lighter
Lumpawaroo

0
Axiomatik avatar Axiomatik 791 Точки

For the tokens = input.split(" -> ") command, even when the user is already  present in the target group, the output message still has to be printed.

Try to change lines 35-43 from:

                } else {
                    if (!forceBook.get(forceSide).contains(forceUser)) {
                        for (List<String> list : forceBook.values()) {
                            list.remove(forceUser);
                        }
 
                        forceBook.get(forceSide).add(forceUser);
                        System.out.printf("%s joins the %s side!%n", forceUser, forceSide);
                    }

to:

                } else {                    
                        for (List<String> list : forceBook.values()) {
                            list.remove(forceUser);
                        }
 
                        forceBook.get(forceSide).add(forceUser);
                        System.out.printf("%s joins the %s side!%n", forceUser, forceSide);
                    

For the input.split(" \\| "); command, try to separate the two validations to see whether a given group and user exist (lines 51-56):

              
                    if (!forceBook.containsKey(forceSide)) {
                        forceBook.put(forceSide, new ArrayList<>());
                    }
                    
                    if (!contains(forceBook, forceUser)) {
                     forceBook.get(forceSide).add(forceUser);
                    }


                

Best,

0