Loading...

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

georgievmartin17 avatar georgievmartin17 6 Точки

Wild ZOO, Ako някой даде идея, как да достъпя valueTo на ареаМапА, ще съм повече от благодарен, прилагам pasteBin, оградил съм в скобите проблема ... Благодаря https://pastebin.com/JtFXGun8

https://pastebin.com/JtFXGun8

 

 

 

Create a program that organizes the daily feeding of animals. You need to keep information about animals, their daily food limit and the areas of the Wildlife Refuge they live in. You will be receiving lines with commands until you receive the "EndDay" message.  There are two possible commands:

  • "Add: {animalName}-{dailyFoodLimit}-{area}":
    • Add the animal and its daily food limit to your records. It is guaranteed that the names of the animals are unique and there will never be animals with the same name. If it already exists, just increase the value of the daily food limit with the current one that is given.
  • "Feed: {animalName}-{food}-{area}":
    • Check if the animal exists and if it does, reduce its daily food limit with the given food for feeding. If its limit reaches 0 or less, the animal is considered successfully fed and you need to remove it from your records and print the following message:
      • "{animalName} was successfully fed"

You need to know the count of hungry animals there are left in each area in the end. If an animal has daily food limit above 0, it is considered hungry.

In the end, you have to print each animal with its daily food limit sorted in descending order by the daily food limit and then by its name in ascending order in the following format:

Animals:

{animalName} -> {dailyFoodLimit}g

{animalName} -> {dailyFoodLimit}g

Afterwards, print the areas with the count of animals, which are not fed in descending order by the count of animals. If an area has 0 hungry animals in it, don't print it. The output must be in the following format:

Areas with hungry animals:

{areaName} : {countOfUnfedAnimals}

{areaName} : {countOfUnfedAnimals}

Input / Constraints

  • You will be receiving lines until you receive the "Last Info" command.
  • The food comes in grams and is an integer number in the range [1...100000].
  • The input will always be valid.
  • There will never be a case, in which an animal is in two or more areas at the same time.

Output

  • Print the appropriate message after the "Feed" command, if an animal is fed.
  • Print the animals with their daily food limit in the format described above.
  • Print the areas with the count of unfed animals in them in the format described above.

Add: Adam-4500-ByTheCreek

Add: Maya-7600-WaterfallArea

Add: Maya-1230-WaterfallArea

Feed: Jamie-2000

EndDay

Animals:

 Adam -> 4500g

 Maya -> 8830g

Areas with hungry animals:

ByTheCreek: 1

WaterfallArea: 1

Add: Jamie-600-WaterfallArea

Add: Maya-6570-WaterfallArea

Add: Adam-4500-ByTheCreek

Add: Bobbie-6570-WaterfallArea

Feed: Jamie-2000

Feed: Adam-2000

Feed: Adam-2500

EndDay

Jamie was successfully fed

Adam was successfully fed

Animals:

 Maya -> 6570g

 Bobbie -> 6570g

Areas with hungry animals:

WaterfallArea: 2

 

Тагове:
0
Java Fundamentals 03/04/2022 20:23:20
MartinBG avatar MartinBG 4803 Точки

Тъй като няма връзка между името на животното и зоната, в която се намира, трябва да обходим всички зони и да премахнем животните с това име:

areaMap.values().forEach(names -> names.remove(nameFed));

 

0
04/04/2022 23:24:11
MarinovMarin avatar MarinovMarin 1 Точки

Hi

Wild Zoo - Pastebin.com

I had a quick look at your way. First problem is you have to look at row 31 and 32 , the check for the area map needs to be indipendent from the feedMap. For the Feed part just have a look at my code, hope it helps. Sorry for the english easier writing on it.

PS If you dont use approach with creating objects in my opinion to connect the 3 paramethers, the first map needs to have enbodied map as Value containing the food and area.

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