Loading...

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

gina78 avatar gina78 4 Точки

Car Salesman

Здравейте колеги,  малко помощ можели

 

това е моето решение стигнах до някъде и блокирах

https://pastebin.com/mW0cT8DK

Car Salesman

Define two classes Car and Engine. A Car has a model, engine, weight and color. An Engine has model, power, displacement and efficiency. A Car’s weight and color and its Engine’s displacements and efficiency are optional.

On the first line you will read a number N which will specify how many lines of engines you will receive, on each of the next N lines you will receive information about an Engine in the following format “<Model> <Power> <Displacement> <Efficiency>”. After the lines with engines, on the next line you will receive a number M – specifying the number of Cars that will follow, on each of the next M lines information about a Car will follow in the following format “<Model> <Engine> <Weight> <Color>”, where the engine in the format will be the model of an existing Engine. When creating the object for a Car, you should keep a reference to the real engine in it, instead of just the engine’s model, note that the optional properties might be missing from the formats.

Your task is to print each car (in the order you received them) and its information in the format defined bellow, if any of the optional fields has not been given print “n/a” in its place instead:

<CarModel>:
  <EngineModel>:
    Power: <EnginePower>
    Displacement: <EngineDisplacement>
    Efficiency: <EngineEfficiency>
  Weight: <CarWeight>
  Color: <CarColor>

Bonus*

Define the magic method __toString() to have a reusable way of displaying the objects.

Examples

Input

Output

2

V8-101 220 50

V4-33 140 28 B

3

FordFocus V4-33 1300 Silver

FordMustang V8-101

VolkswagenGolf V4-33 Orange

FordFocus:

  V4-33:

    Power: 140

    Displacement: 28

    Efficiency: B

  Weight: 1300

  Color: Silver

FordMustang:

  V8-101:
    Power: 220
    Displacement: 50

    Efficiency: n/a

  Weight: n/a

  Color: n/a

VolkswagenGolf:

  V4-33:

    Power: 140

    Displacement: 28

    Efficiency: B

  Weight: n/a

  Color: Orange

4

DSL-10 280 B

V7-55 200 35

DSL-13 305 55 A+

V7-54 190 30 D

4

FordMondeo DSL-13 Purple

VolkswagenPolo V7-54 1200 Yellow

VolkswagenPassat DSL-10 1375 Blue

FordFusion DSL-13

FordMondeo:

  DSL-13:

    Power: 305

    Displacement: 55

    Efficiency: A+

  Weight: n/a

  Color: Purple

VolkswagenPolo:

  V7-54:

    Power: 190

    Displacement: 30

    Efficiency: D

  Weight: 1200

  Color: Yellow

VolkswagenPassat:

  DSL-10:

    Power: 280

    Displacement: n/a

    Efficiency: B

  Weight: 1375

  Color: Blue

FordFusion:

  DSL-13:

    Power: 305

    Displacement: 55

    Efficiency: A+

  Weight: n/a

  Color: n/a

Тагове:
0
PHP Web 12/11/2019 19:07:48
gina78 avatar gina78 4 Точки

Благодаря ти много

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