OOP Изпит 12.Декември 2020 г.
Колеги, някой може ли да сподели решение на днешния изпит, че само тестовете минаха на 100/100?
Колеги, някой може ли да сподели решение на днешния изпит, че само тестовете минаха на 100/100?
Би трябвало класовете "контролер" и "маса" да изглеждат подобно
контролер
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Bakery.Core.Contracts;
using Bakery.Models;
using Bakery.Models.BakedFoods;
using Bakery.Models.BakedFoods.Contracts;
using Bakery.Models.Drinks;
using Bakery.Models.Drinks.Contracts;
using Bakery.Models.Tables;
using Bakery.Models.Tables.Contracts;
using Bakery.Utilities.Enums;
using Bakery.Utilities.Messages;
namespace Bakery.Core
{
public class Controller : IController
{
private readonly ICollection<object> resturantObjects; /// за максимална капсулация,но може и с три колекции
private decimal totalSumResturant;
public Controller()
{
resturantObjects = new List<object>();
}
public string AddDrink(string type, string name, int portion, string brand)
{
IDrink drink = null;
DrinkType drinkType;
bool parsed = Enum.TryParse<DrinkType>(type, out drinkType);
if (parsed)
{
if (drinkType == DrinkType.Tea)
{
drink = new Tea(name, portion, brand);
}
else if (drinkType == DrinkType.Water)
{
drink = new Water(name, portion, brand);
}
}
resturantObjects.Add(drink);
return $"Added {drink.Name} ({drink.Brand}) to the drink menu";
}
public string AddFood(string type, string name, decimal price)
{
IBakedFood food = null;
if (type == "Bread")
{
food = new Bread(name, price);
}
else if (type == "Cake")
{
food = new Cake(name, price);
}
else
{
}
resturantObjects.Add(food);
return $"Added {food.Name} ({food.GetType().Name}) to the menu";
}
public string AddTable(string type, int tableNumber, int capacity)
{
ITable table = null;
if (type == "InsideTable")
{
table = new InsideTable(tableNumber, capacity);
}
else if (type == "OutsideTable")
{
table = new OutsideTable(tableNumber, capacity);
}
else
{
}
resturantObjects.Add(table);
return $"Added table number { table.TableNumber} in the bakery";
}
public string GetFreeTablesInfo()
{
StringBuilder sb = new StringBuilder();
foreach (var table in resturantObjects)
{
if (table is ITable && !(table as ITable).IsReserved)
{
sb.AppendLine((table as ITable).GetFreeTableInfo());
}
}
return sb.ToString().TrimEnd();
}
public string GetTotalIncome()
{
return $"Total income: { totalSumResturant:f2}lv";
}
public string LeaveTable(int tableNumber)
{
ITable table = resturantObjects.FirstOrDefault(t =>t is ITable && (t as ITable).TableNumber == tableNumber) as ITable;
decimal totalSum = table.GetBill();
totalSumResturant += table.GetBill();
table.Clear();
return $"Table: {tableNumber}\nBill: {totalSum:f2}";
}
public string OrderDrink(int tableNumber, string drinkName, string drinkBrand)
{
ITable table = resturantObjects.FirstOrDefault(t => t is ITable && (t as ITable).TableNumber == tableNumber) as ITable;
if (table == null)
{
return $"Could not find table { tableNumber}";
}
else
{
IDrink drink = resturantObjects.FirstOrDefault(d => d is IDrink && (d as IDrink).Name == drinkName) as IDrink;
if (drink == null || drink.Brand != drinkBrand)
{
return $"There is no {drinkName} {drinkBrand} available";
}
else
{
table.OrderDrink(drink);
return $"Table {tableNumber} ordered {drinkName} {drinkBrand}";
}
}
}
public string OrderFood(int tableNumber, string foodName)
{
ITable table = resturantObjects.FirstOrDefault(t => t is ITable && (t as ITable).TableNumber == tableNumber ) as ITable;
if (table == null)
{
return $"Could not find table { tableNumber}";
}
else
{
IBakedFood food = resturantObjects.FirstOrDefault(f => f is IBakedFood && (f as IBakedFood).Name == foodName) as IBakedFood;
if (food == null)
{
return $"No {foodName} in the menu";
}
else
{
table.OrderFood(food);
return $"Table {tableNumber} ordered {foodName}";
}
}
}
public string ReserveTable(int numberOfPeople)
{
ITable table = resturantObjects.FirstOrDefault(t => t is ITable && !((t as ITable).IsReserved)) as ITable;
if (table == null || table.Capacity < numberOfPeople)
{
return string.Format(OutputMessages.ReservationNotPossible,numberOfPeople);
}
else
{
table.Reserve(numberOfPeople);
return $"Table {table.TableNumber} has been reserved for {numberOfPeople} people";
}
}
}
}
маса
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bakery.Models.BakedFoods;
using Bakery.Models.BakedFoods.Contracts;
using Bakery.Models.Drinks.Contracts;
using Bakery.Models.Tables.Contracts;
namespace Bakery.Models.Tables
{
public abstract class Table : ITable,IObjects
{
private List<IBakedFood> foodOrders;
private List<IDrink> drinkOrders;
private int capacity;
protected Table(int tableNumber, int capacity, decimal pricePerPerson)
{
TableNumber = tableNumber;
Capacity = capacity;
PricePerPerson = pricePerPerson;
foodOrders = new List<IBakedFood>();
drinkOrders = new List<IDrink>();
}
public int TableNumber { get; }
public int Capacity
{
get
{
return capacity;
}
private set
{
if (value < 0)
{
throw new ArgumentException("Capacity has to be greater than 0");
}
capacity = value;
}
}
public int NumberOfPeople { get; private set; }
public decimal PricePerPerson { get; }
public bool IsReserved{ get; private set; }
public decimal Price => PricePerPerson * NumberOfPeople;
public void Clear()
{
foodOrders.Clear();
drinkOrders.Clear();
Capacity += NumberOfPeople;
IsReserved = false;
NumberOfPeople = 0;
}
public decimal GetBill()
{
decimal totalSum = foodOrders.Sum(f => f.Price) + drinkOrders.Sum(d => d.Price) + Price;
return totalSum;
}
public string GetFreeTableInfo()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Table: {TableNumber}");
sb.AppendLine($"Type: {GetType().Name}");
sb.AppendLine($"Capacity: {Capacity}");
sb.AppendLine($"Price per Person: {PricePerPerson}");
return sb.ToString().TrimEnd();
}
public void OrderDrink(IDrink drink)
{
if (IsReserved == true)
{
drinkOrders.Add(drink);
}
}
public void OrderFood(IBakedFood food)
{
if (IsReserved == true)
{
foodOrders.Add(food);
}
}
public void Reserve(int NPeople)
{
if (NPeople <= 0)
{
throw new ArgumentException("Cannot place zero or less people!");
}
IsReserved = true;
NumberOfPeople = NPeople;
Capacity -= NumberOfPeople;
}
}
}
Здравей,
Малко късно, но ако все още те интересува този изпит ти предлагам едно решение което взима всички точки от judge.
https://github.com/MiroslavPeychev/C-Sharp-OOP/tree/master/C%23%20OOP%20Exam%20-%2012%20December%202020
Поздрави,
Мирослав
I just joined the forum so there are so many things I don’t know yet, I hope to have the help of the boards, and I really want to get to know you all on the forum basketball legends
Здравейте,
някой ако има време може ли да погледне моето решение, което е 94/150.
Излизат ми правилните аутпути, но Judge показва, че цели 7 теста гърмят. Вече няколко дена се връщам отново и отново на задачата, но без резултат. От преглеждането на други решение и сравнявайки ги с моето не намирам големи разлики, но така и не си откривам грешката.
Тук е условието - https://judge.softuni.bg/Contests/Practice/Index/2685#1
Поздрави!