Професионална програма
Loading...
dido1092 avatar dido1092 37 Точки

C# OOP Exercise: Encapsulation

Здравейте имам нужда от помощ със следната задача.

Условие

3.Shopping Spree

Create two classes: class Person and class Product. Each person should have a name, money and a bag of products. Each product should have a name and a cost. Name cannot be an empty string. Money cannot be a negative number.

Create a program in which each command corresponds to a person buying a product. If the person can afford a product, add it to his bag. If a person doesn’t have enough money, print an appropriate message ("{personName} can't afford {productName}").

On the first two lines you are given all people and all products. After all purchases print every person in the order of appearance and all products that he has bought also in order of appearance. If nothing was bought, print the name of the person followed by "Nothing bought".

In case of invalid input (negative money Exception message: "Money cannot be negative") or an empty name (empty name Exception message: "Name cannot be empty") break the program with an appropriate message. See the examples below:

Examples

Input

Output

Pesho=11;Gosho=4

Bread=10;Milk=2;

Pesho Bread

Gosho Milk

Gosho Milk

Pesho Milk

END

Pesho bought Bread

Gosho bought Milk

Gosho bought Milk

Pesho can't afford Milk

Pesho - Bread

Gosho - Milk, Milk

Mimi=0

Kafence=2

Mimi Kafence

END

Mimi can't afford Kafence

Mimi - Nothing bought

Jeko=-3

Chushki=1;

Jeko Chushki

END

Money cannot be negative

 

 

Моят код: https://dox.abv.bg/download?id=2403bc3a71

Дава ми 80/100 не разбирам къде ми е грешката, предварително благодаря!

Тагове:
0
C# OOP Advanced
icowwww avatar icowwww 1453 Точки
Best Answer

Здравей,

В класа Product имаш грешка при сетване на отрицателна стойност за Cost- текста на грешката ти е:

Cost cannot be negative,

а по условие трябва да е:

Money cannot be negative

1
dido1092 avatar dido1092 37 Точки

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

0