Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

NMKrastev avatar NMKrastev 0 Точки

04. Teamwork Projects - Objects and Classes - More Exercise

Здравейте,

Имам затруднения със посочената задача, като не намирам къде точно бърквам в кода. Judge ми дава 83/100 като гърми Test #1.

 

Условие:

It's time for teamwork projects and you are responsible for making the teams. First you will receive an integer - the count of the teams you will have to register. You will be given a user and a team (separated with “-”).  The user is the creator of that team.

For every newly created team you should print a message:

"Team {team Name} has been created by {user}!".

Next you will receive user with team (separated with "->") which means that the user wants to join that team. Upon receiving the command: “end of assignment”, you should print every teamordered by the count of its members (descending) and then by name (ascending). For each team (disband teams as well), you have to print its members sorted by name (ascending). However, there are several rules:

  1. If user tries to create a team more than once a message should be displayed:
    • "Team {teamName} was already created!"
  2. Creator of a team cannot create another team - message should be thrown:
    • "{user} cannot create another team!"
  3. If user tries to join currently non-existing team a message should be displayed:
    • "Team {teamName} does not exist!"
  4. Member of a team cannot join another team - message should be thrown:
    • "Member {user} cannot join team {team Name}!"
  5. In the end (after teams' report) teams with zero members (with only a creator) should disband ordered by name in ascending other.
  6.  Every valid team should be printed ordered by name (ascending) in this format:

        "{teamName}:
          - {create}
          -- {member}...
"

Входни/Изходни данни:

Input

Output

Comments

2

Didy-PowerPuffsCoders

Tony-Tony is the best

Petya->PowerPuffsCoders

Tony->Tony is the best

end of assignment

Team PowerPuffsCoders has been created by Didy!

Team Tony is the best has been created by Tony!

Member Tony cannot join team Tony is the best!

PowerPuffsCoders

- Didy

-- Petya

Teams to disband:

Tony is the best

Tony created a team that he tried later to join. So the message was shown. Since no one is trying to join his team, the team has to disband.

3

Tatyana-CloneClub

Helena-CloneClub

Trifon-BRBClub

Peter->bRBClub

Peter->BRBClub

Tatyana->Leda

Petter->BRBClub

Cossima->CloneClub

end of assignment

Team CloneClub has been created by Tatyana!

Team CloneClub was already created!

Team BRBClub has been created by Trifon!

Team bRBClub does not exist!

Team Leda does not exist!

BRBClub

- Trifon

-- Peter

-- Petter

CloneClub

- Tatyana

-- Cossima

Teams to disband:

Note that when you join a team, you should check first if it exists, then check if the user is already in a team:

Tatyana has created CloneClub, and then she tries to join a non-existing team – so a message for the non-existing team is shown.

 

Кода, който съм написал е следния: https://pastebin.com/a1yiWvf7

Ще съм благодарен, ако ми дадете насоки, затова къде греша.

0
Java Fundamentals 27/10/2022 23:27:29
icowwww avatar icowwww 2673 Точки
Best Answer

Здравей,

В условието пише print every team, ordered by the count of its members (descending) and then by name (ascending)

При теб е обратното- първо по име и после по брой членове.

Промени 53и 54 ред от:

        teamsList.sort(Comparator.comparing(Team::getTeam)
                .thenComparing(Comparator.comparingInt(Team::getNumberOfMembers).reversed()));

На:

        teamsList.sort(Comparator.comparingInt(Team::getNumberOfMembers).reversed().thenComparing(Team::getTeam));

 

0
NMKrastev avatar NMKrastev 0 Точки

Много благодаря, колега! Това беше разковничето, но който не дочита или не прочита правилно - така ще е. 

Още веднъж благодарности! :)

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.