Софтуерно Инженерство
Vasetoo0 avatar Vasetoo0 5 Точки

06. Pokemon Trainer - DefiningClasses - Java Advanced Малко Помощ?

Здрвейте колеги, от 4 часа съм зациклил какво ли не пробвах и вече блокирах тотално. На два от тестовете ми дава Runtime Error. Не можах да открия защо, моля ако някой може да помогне?

Ето условието:

1.Pokémon Trainer

You wanna be the very best pokemon trainer, like no one ever was, so you set out to catch pokemons. Define a class Trainer and a class Pokemon. Trainer have a name, number of badges and a collection of pokemon. Pokemon have a name, an element and health, all values are mandatory. Every Trainer starts with 0 badges.

From the console you will receive an unknown number of lines until you receive the command "Tournament", each line will carry information about a pokemon and the trainer who caught it in the format "<TrainerName> <PokemonName> <PokemonElement> <PokemonHealth>" where TrainerName is the name of the Trainer who caught the pokemon, names are unique there cannot be 2 trainers with the same name. After receiving the command "Tournament" an unknown number of lines containing one of three elements "Fire", "Water", "Electricity" will follow until the command "End" is received. For every command you must check if a trainer has atleast 1 pokemon with the given element, if he does he receives 1 badge, otherwise all his pokemon lose 10 health, if a pokemon falls to 0 or less health he dies and must be deleted from the trainer’s collection. After the command "End" is received you should print all trainers sorted by the amount of badges they have in descending order (if two trainers have the same amount of badges they should be sorted by order of appearance in the input) in the format "<TrainerName> <Badges> <NumberOfPokemon".




Pesho Charizard Fire 100

Gosho Squirtle Water 38

Pesho Pikachu Electricity 10





Pesho 2 2

Gosho 0 1

Stamat Blastoise Water 18

Nasko Pikachu Electricity 22

Jicata Kadabra Psychic 90






Nasko 1 1

Stamat 0 0

Jicata 0 1

Това ми е Решението:

Main class:https://pastebin.com/0wgy4QZu 

Trainer class:https://pastebin.com/LTzfJRzn

Pokemon class:https://pastebin.com/bTDhS5aN

Линк към Judge:https://judge.softuni.bg/Contests/Compete/Index/1518#5

Благодаря предварително!

Java Advanced
Hristo13 avatar Hristo13 235 Точки
Best Answer

Здравей проблема ти идва от това че премахваш от листа покемони под 10hp вътре в итератора.
Ето оправен кода за сверка ако случайно намериш затруднения:

Main -  https://pastebin.com/Up09S8wy

Trainer - https://pastebin.com/mhcrEVQw

10/06/2019 20:55:52
Vasetoo0 avatar Vasetoo0 5 Точки

Благодаря колега!