C# OOP - Shopping Spree
Здравейте! Имам затруднения с една задачка. Judge се сърди и ми дава 80/100. Ако някой има идея от къде идва грешката, ще съм благодарен да сподели!
Код: https://github.com/Statev7/SoftUni/tree/main/C03_C%23OOP-October-2021/04_Encapsulation%20-%20Exercise/P03_ShoppingSpree
Условие:
Problem 1.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 |