Loading...

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

Olegati avatar Olegati 7 Точки

07. Google 80/100 (Defining Classes - Exercises)

Здравейте, 

На 7 задача от Defining Classes - Exercises в Judge 4-тият тест не минава. Предполагам, че грешката е в листовете pokemons, parents и children, другия вариант е в toString() метода на класа Person. Ако някой открие грешката, моля да сподели :)

Класове: 

Main -> https://pastebin.com/Hw3RxYnG

Person -> https://pastebin.com/ysLk0MuB

Company -> https://pastebin.com/Cz1hTV70

Car -> https://pastebin.com/DcnQPRTW

Pokemon -> https://pastebin.com/sJEtVESz

Parents -> https://pastebin.com/BxGpg5Af

Children -> https://pastebin.com/dgzmGwDZ

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


Условие: 

Google

Google is always watching you, so it should come as no surprise that they know everything about you (even your pokemon collection), since you’re a really good at writing classes, Google asked you to design a Class that can hold all the information they need for people.

You will receive an unknown number of rows from the console until you receive the "End" command, on each of those lines there will be information about a person in one of the following formats:

  • "{Name} company {companyName} {department} {salary}
  • "{Name} pokemon {pokemonName} {pokemonType}"
  • "{Name} parents {parentName} {parentBirthday}"
  • "{Name} children {childName} {childBirthday}"
  • "{Name} car {carModel} {carSpeed}"

You should structure all information about a person in a class with nested subclasses. People names are unique - there won't be 2 people with the same name, a person can also have only 1 company and car, but can have multiple parents, children and pokemons. After the command "End" is received on the next line you will receive a single name, you should print all information about that person. Note that information can change during the input, for instance if we receive multiple lines which specify a person company, only the last one should be the one remembered. The salary must be formated to two decimal places after the seperator.

Note: print the information in format:

                {personName}

      Company:

      {companyName} {companyDepartment} {salary}

      ...

      Children:

      {childName} {childBirthday}

      {childName} {childBirthday}

Examples

Input

Output

PeterSmith company PeshInc Management 1000.00

JohnJohnson car Trabant 30

PeterSmith pokemon Pikachu Electricity

PeterSmith parents PoshoPeshev 22/02/1920

JohnJohnson pokemon Electrode Electricity

End

JohnJohnson

JohnJohnson

Company:

Car:

Trabant 30

Pokemon:

Electrode Electricity

Parents:

Children:

GeorgeJohnson pokemon Onyx Rock

GeorgeJohnson parents SaraJohnson 13/03/1933

AlexAlexson pokemon Moltres Fire

GeorgeJohnson company JeleInc Jelior 777.77

GeorgeJohnson children SamJohnson 01/01/2001

SmithSmithon pokemon Blastoise Water

GeorgeJohnson car AudiA4 180

GeorgeJohnson pokemon Charizard Fire

End

GeorgeJohnson

GeorgeJohnson

Company:

JeleInc Jelior 777.77

Car:

AudiA4 180

Pokemon:

Onyx Rock

Charizard Fire

Parents:

SaraJohnson 13/03/1933

Children:

SamJohnson 01/01/2001

Тагове:
0
Java Advanced
icowwww avatar icowwww 2673 Точки

Здравей,

В условието пише: The salary must be formated to two decimal places after the seperator. Ти я пазиш в стринг и просто я принтираш.

Затова един бърз фикс в клас Company:

https://pastebin.com/FGkJXJGb

Въпреки че това дава 100/100, Main метода може доста да се намали и опрости като просто провериш дали имаш такъв Person, ако не- да го добавиш и после да продължиш само със случая, в който го има:

https://pastebin.com/au28becu

 

0
07/10/2021 23:11:04
Olegati avatar Olegati 7 Точки

Благодаря! Не бях забелязал условието за Salary и main-a изглежда по-добре yes

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