Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fedulova polina nikolaevna #26

Open
wants to merge 8 commits into
base: Fedulova_Polina_Nikolaevna
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions CourseApp.Tests/DishTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
namespace CourseApp.Tests
{
using CourseApp.Class;
using Xunit;

public class DishTests
{
[Fact]
public void SushiConstructorTest()
{
Dish sushi = new Sushi("California", 176, 28, 350, "Standard", 8);
Assert.Equal(
@"Sushi: California
Callories: 176
Weight: 28
Price: 350
Type: Standard", sushi.GetInfo());
}

[Fact]
public void SaladConstructorTest()
{
Dish salad = new Salad("Caesar", 44, 300, new string[] { "chicken", "cherry", "tomatoes", "parmesan", "olive oil", "garlic", "black pepper" }, 400);
Assert.Equal(
@"Salad: Caesar
Callories: 44
Weight: 300
Price: 400", salad.GetInfo());
}

[Fact]
public void EmptyConstructorTest()
{
Dish dish = new Salad();
Assert.Equal(
@"Salad: No_Name_Null
Callories: 0
Weight: 0
Price: 0", dish.GetInfo());
}

[Fact]
public void ToStringTest()
{
Dish dish = new Sushi("California", 176, 28, 350, "standard", 8);
Assert.Equal("Sushi California - standard", dish.ToString());
}

[Fact]
public void AbstractMethodTest()
{
Dish sushi = new Sushi("California", 176, 28, 350, "standard", 8);
Assert.Equal("We eat one sushi", sushi.Eat());
}

[Fact]
public void TestInterfacesDelivery()
{
Salad dish = new Salad("Caesar", 44, 300, new string[] { "chicken", "cherry", "tomatoes", "parmesan", "olive oil", "garlic", "black pepper" }, 400);
int newPrice = (int)(dish.Price * 1.3);
dish.Delivery();
Assert.Equal(
$@"Salad: Caesar
Callories: 44
Weight: 300
Price: {newPrice}", dish.GetInfo());
}

[Fact]
public void TestInterfaceCooking()
{
Salad dish = new Salad();
Assert.Equal("Salad prepared and dressed", dish.CookingDish(new string[] { "ingredients" }));
}
}
}
131 changes: 131 additions & 0 deletions CourseApp/Class/Dish.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
namespace CourseApp.Class
{
using System;

public abstract class Dish
{
private string name;
private double callories;
private double weight;
private double price;

public Dish()
{
callories = 0;
weight = 0;
name = "No_Name_Null";
price = 0;
}

public Dish(string name, double callories, double weight, double price)
{
Callories = callories;
Weight = weight;
Name = name;
Price = price;
}

public string Name
{
get
{
return name;
}

set
{
try
{
if ((value == " ") || (value == null))
{
throw new Exception($"Name is incorrect!");
}
else
{
name = value;
}
}
catch (Exception e)
{
new ArgumentException($"Error: {e.Message}");
Console.WriteLine($"Error: {e.Message}");
}
}
}

public double Price
{
get
{
return price;
}

set
{
if (value < 0)
{
price = 0;
}
else
{
price = value;
}
}
}

public double Callories
{
get
{
return callories;
}

set
{
if (value < 0)
{
callories = 0;
}
else
{
callories = value;
}
}
}

public double Weight
{
get
{
return weight;
}

set
{
if (value < 0)
{
weight = 0;
}
else
{
weight = value;
}
}
}

public virtual string GetInfo()
{
return @$"Dish: {Name}
Callories: {Callories}
Weight: {Weight}
Price: {Price}";
}

public override string ToString()
{
return $"Блюдо: {name} Цена:{Price}";
}

public abstract string Eat();
}
}
7 changes: 7 additions & 0 deletions CourseApp/Class/ICookingDish.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace CourseApp.Class
{
public interface ICookingDish
{
public string CookingDish(string[] ingredients);
}
}
7 changes: 7 additions & 0 deletions CourseApp/Class/IDeliverDish.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace CourseApp.Class
{
public interface IDeliverDish
{
public void Delivery();
}
}
28 changes: 28 additions & 0 deletions CourseApp/Class/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace CourseApp
{
using System.Collections.Generic;
using CourseApp.Class;

public class Program
{
public static void Main(string[] args)
{
Dish sushi = new Sushi("California", 176, 28, 350, "standard", 8);
Dish salad = new Salad("Caesar", 44, 300, new string[] { "chicken", "cherry", "tomatoes", "parmesan", "olive oil", "garlic", "black pepper" }, 400);
List<Dish> dishs = new List<Dish> { salad, sushi };
System.Console.WriteLine(sushi.ToString());
System.Console.WriteLine(salad.ToString());

for (int i = 0; i < dishs.Count; i++)
{
System.Console.WriteLine(dishs[i].Eat());
}

Dish dish = new Salad();
System.Console.WriteLine(dish.GetInfo());

Salad salad1 = new Salad("Caesar", 44, 300, new string[] { "chicken", "cherry", "tomatoes", "parmesan", "olive oil", "garlic", "black pepper" }, 400);
salad1.Delivery();
}
}
}
53 changes: 53 additions & 0 deletions CourseApp/Class/Salad.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace CourseApp.Class
{
public class Salad : Dish, IDeliverDish, ICookingDish
{
public Salad(string name, double callories, double weight, string[] composition, double price)
: base(name, callories, weight, price)
{
Composition = composition;
}

public Salad()
{
}

public string[] Composition
{
get; set;
}

public override string GetInfo()
{
return @$"Salad: {Name}
Callories: {Callories}
Weight: {Weight}
Price: {Price}";
}

public override string Eat()
{
Weight = 0.8 * Weight;
return "We eat part of the salad";
}

public override string ToString()
{
return $"Salad {Name}, {Callories} callories";
}

public void Delivery()
{
Price = (int)(Price * 1.3);
System.Console.WriteLine($"Your salad delivered");
}

public string CookingDish(string[] ingredients)
{
Composition = ingredients;

Callories *= 1.2;
return "Salad prepared and dressed";
}
}
}
62 changes: 62 additions & 0 deletions CourseApp/Class/Sushi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using CourseApp.Class;

public class Sushi : Dish
{
private int number;

public Sushi(string name, double callories, double weight, double price, string type, int number)
: base(name, callories, weight, price)
{
TypeOfSuchi = type;
this.number = number;
}

public Sushi()
{
}

public int Number
{
get
{
return number;
}

set
{
if (value < 0)
{
number = 0;
}
}
}

public string TypeOfSuchi { get; set; }

public override string ToString()
{
return $"Sushi {Name} - {TypeOfSuchi}";
}

public override string GetInfo()
{
return @$"Sushi: {Name}
Callories: {Callories}
Weight: {Weight}
Price: {Price}
Type: {TypeOfSuchi}";
}

public override string Eat()
{
if (number > 0)
{
number -= 1;
return "We eat one sushi";
}
else
{
return "We can't eat sushi because there isn't any";
}
}
}
Loading