diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index cf7cbb1..d211ca0 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -1,5 +1,6 @@ namespace CourseApp.Tests { + using Phones; using Xunit; public class DemoTest @@ -9,5 +10,25 @@ public void Test1() { Assert.True(true); } + + [Fact] + public void TestCreatePhone() + { + var phone = new LandlinePhone("123", "Name", -1); + Assert.Equal("Name", phone.Name); + Assert.Equal(1880, phone.Year); + } + + [Theory] + [InlineData(5, 12, 12)] + [InlineData(5, -1, 5)] + [InlineData(5, 20, 5)] + public void TestDiagonal(int initial, int change, int expected) + { + var phone = new CellPhone("123", "Name", initial); + Assert.Equal(5, phone.Diagonal); + phone.Diagonal = change; + Assert.Equal(expected, phone.Diagonal); + } } } diff --git a/CourseApp/Phone.cs b/CourseApp/Phone.cs deleted file mode 100644 index 1c8e407..0000000 --- a/CourseApp/Phone.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace CourseApp -{ - using System; - - public class Phone - { - private float diaonal; - - public Phone(string name, float diagonal) - { - Name = name; - Diagonal = diagonal; - } - - public string Name { get; set; } - - public float Diagonal - { - get - { - return diaonal; - } - - set - { - if (value > 0 && value < 20) - { - this.diaonal = value; - } - } - } - - public void Show() - { - Console.WriteLine($"{Name} with diagonal {diaonal}"); - } - } -} \ No newline at end of file diff --git a/CourseApp/Phones/AndroidPhone.cs b/CourseApp/Phones/AndroidPhone.cs new file mode 100644 index 0000000..19a0bb3 --- /dev/null +++ b/CourseApp/Phones/AndroidPhone.cs @@ -0,0 +1,21 @@ +namespace Phones +{ + public class AndroidPhone : SmartPhone + where T : IAndroidApp + { + public AndroidPhone() + : base("+70000000", "Pixel", 2022) + { + } + + public AndroidPhone(string number, string name, int diagonal) + : base(number, name, diagonal) + { + } + + public override void AddApp(T app) + { + base.AddApp(app); + } + } +} \ No newline at end of file diff --git a/CourseApp/Phones/Application.cs b/CourseApp/Phones/Application.cs new file mode 100644 index 0000000..56b76d8 --- /dev/null +++ b/CourseApp/Phones/Application.cs @@ -0,0 +1,16 @@ +namespace Phones +{ + public abstract class Application : IApplication + { + public Application(string name) + { + this.Name = name; + } + + public string Name { get; set; } + + public abstract void InstallApp(); + + public abstract void RunApp(); + } +} \ No newline at end of file diff --git a/CourseApp/Phones/CellPhone.cs b/CourseApp/Phones/CellPhone.cs new file mode 100644 index 0000000..2a85378 --- /dev/null +++ b/CourseApp/Phones/CellPhone.cs @@ -0,0 +1,70 @@ +namespace Phones +{ + using System; + + public class CellPhone : Phone + { + private float diagonal; + + public CellPhone() + : base("+70000000", "nokia", 2) + { + Console.WriteLine("Cell phone without params"); + } + + public CellPhone(string number, string name, int diagonal) + : base(number, name, 2000) + { + this.Diagonal = diagonal; + Console.WriteLine("Cell phone with params"); + } + + public float Diagonal + { + get + { + return diagonal; + } + + set + { + if (value > 0 && value < 20) + { + this.diagonal = value; + } + } + } + + public string TrackName { get; set; } + + public void DeclineCall() + { + Console.WriteLine("Decline Call"); + } + + public void GetMessage() + { + Console.WriteLine("Getting text message"); + } + + public void SendMessage() + { + Console.WriteLine("Sending message"); + } + + public void PlayMusic() + { + Console.WriteLine($"Сейчас играет {TrackName}"); + } + + public override string ToString() + { + return $"Сотовый телефон {Name} номер:{Number}, произведен {Year}"; + } + + public override string Display() + { + return this.ToString(); + } + } +} \ No newline at end of file diff --git a/CourseApp/Phones/FaceTime.cs b/CourseApp/Phones/FaceTime.cs new file mode 100644 index 0000000..9c19535 --- /dev/null +++ b/CourseApp/Phones/FaceTime.cs @@ -0,0 +1,27 @@ +namespace Phones +{ + using System; + + public class FaceTime : Application, IIOsApp + { + public FaceTime(string name) + : base(name) + { + } + + public void CheckWallet() + { + Console.WriteLine("Checking FaceTimeApp"); + } + + public override void InstallApp() + { + Console.WriteLine("Installing FaceTime"); + } + + public override void RunApp() + { + Console.WriteLine("Running FaceTime"); + } + } +} \ No newline at end of file diff --git a/CourseApp/Phones/IAndroidApp.cs b/CourseApp/Phones/IAndroidApp.cs new file mode 100644 index 0000000..b5b05d6 --- /dev/null +++ b/CourseApp/Phones/IAndroidApp.cs @@ -0,0 +1,7 @@ +namespace Phones +{ + public interface IAndroidApp : IApplication + { + public void CheckGoogle(); + } +} \ No newline at end of file diff --git a/CourseApp/Phones/IApplication.cs b/CourseApp/Phones/IApplication.cs new file mode 100644 index 0000000..58e3000 --- /dev/null +++ b/CourseApp/Phones/IApplication.cs @@ -0,0 +1,9 @@ +namespace Phones +{ + public interface IApplication + { + public void InstallApp(); + + public void RunApp(); + } +} \ No newline at end of file diff --git a/CourseApp/Phones/IDisplayable.cs b/CourseApp/Phones/IDisplayable.cs new file mode 100644 index 0000000..879fd74 --- /dev/null +++ b/CourseApp/Phones/IDisplayable.cs @@ -0,0 +1,7 @@ +namespace Phones +{ + public interface IDisplayable + { + public string Display(); + } +} \ No newline at end of file diff --git a/CourseApp/Phones/IIosApp.cs b/CourseApp/Phones/IIosApp.cs new file mode 100644 index 0000000..4871385 --- /dev/null +++ b/CourseApp/Phones/IIosApp.cs @@ -0,0 +1,7 @@ +namespace Phones +{ + public interface IIOsApp : IApplication + { + public void CheckWallet(); + } +} \ No newline at end of file diff --git a/CourseApp/Phones/IOSPhone.cs b/CourseApp/Phones/IOSPhone.cs new file mode 100644 index 0000000..dcfb7f0 --- /dev/null +++ b/CourseApp/Phones/IOSPhone.cs @@ -0,0 +1,16 @@ +namespace Phones +{ + public class IOSPhone : SmartPhone + where T : IIOsApp + { + public IOSPhone() + : this("+70000000", "Pixel", 2022) + { + } + + public IOSPhone(string number, string name, int diagonal) + : base(number, name, diagonal) + { + } + } +} \ No newline at end of file diff --git a/CourseApp/Phones/KeepApp.cs b/CourseApp/Phones/KeepApp.cs new file mode 100644 index 0000000..2122db0 --- /dev/null +++ b/CourseApp/Phones/KeepApp.cs @@ -0,0 +1,27 @@ +namespace Phones +{ + using System; + + public class KeepApp : Application, IAndroidApp + { + public KeepApp(string name) + : base(name) + { + } + + public void CheckGoogle() + { + Console.WriteLine("Big brother watching you!"); + } + + public override void InstallApp() + { + Console.WriteLine("Installing Keep"); + } + + public override void RunApp() + { + Console.WriteLine("Running Keep"); + } + } +} \ No newline at end of file diff --git a/CourseApp/Phones/LandlinePhone.cs b/CourseApp/Phones/LandlinePhone.cs new file mode 100644 index 0000000..db03b3b --- /dev/null +++ b/CourseApp/Phones/LandlinePhone.cs @@ -0,0 +1,25 @@ +namespace Phones +{ + public class LandlinePhone : Phone, IDisplayable + { + public LandlinePhone() + : base("+70000000", "Проводной", 2) + { + } + + public LandlinePhone(string number, string name, int year) + : base(number, name, year) + { + } + + public override string ToString() + { + return $"Проводной телефон {Name} номер:{Number}, произведен {Year}"; + } + + public override string Display() + { + return this.ToString(); + } + } +} \ No newline at end of file diff --git a/CourseApp/Phones/Pen.cs b/CourseApp/Phones/Pen.cs new file mode 100644 index 0000000..eca55b6 --- /dev/null +++ b/CourseApp/Phones/Pen.cs @@ -0,0 +1,10 @@ +namespace Phones +{ + public class Pen : IDisplayable + { + public string Display() + { + return "Smart pen"; + } + } +} \ No newline at end of file diff --git a/CourseApp/Phones/Phone.cs b/CourseApp/Phones/Phone.cs new file mode 100644 index 0000000..90e52b8 --- /dev/null +++ b/CourseApp/Phones/Phone.cs @@ -0,0 +1,60 @@ +namespace Phones +{ + using System; + + public abstract class Phone : IDisplayable + { + private int year = 1880; + + public Phone() + : this("+7000000", "untitled", 1990) + { + Console.WriteLine("Phone Simple constructor called"); + } + + public Phone(string number, string name, int year) + { + Number = number; + Year = year; + Name = name; + Console.WriteLine("Phone constructor called"); + } + + public string Name { get; set; } + + public string Number { get; set; } + + public int Year + { + get + { + return year; + } + + set + { + if (value >= 1880 && value <= 2022) + { + this.year = value; + } + } + } + + public void AcceptCall() + { + Console.WriteLine("Принимаю звонок"); + } + + public void CloseCall() + { + Console.WriteLine("Завершаю звонок"); + } + + public void MakeCall(string phoneNumber) + { + Console.WriteLine($"Звонок на номер {phoneNumber}"); + } + + public abstract string Display(); + } +} \ No newline at end of file diff --git a/CourseApp/Phones/Smartphone.cs b/CourseApp/Phones/Smartphone.cs new file mode 100644 index 0000000..75709d6 --- /dev/null +++ b/CourseApp/Phones/Smartphone.cs @@ -0,0 +1,59 @@ +namespace Phones +{ + using System; + using System.Collections.Generic; + + public class SmartPhone : CellPhone, IDisplayable + where T : IApplication + { + private List apps; + + public SmartPhone() + : this("+70000000", "Pixel", 2022) + { + } + + public SmartPhone(string number, string name, int diagonal) + : base(number, name, diagonal) + { + apps = new List(); + } + + public string OsType { get; set; } + + public override string ToString() + { + return $"Проводной телефон {Name} номер:{Number}, произведен {Year}"; + } + + public override string Display() + { + return this.ToString(); + } + + public void ConnectToInternet() + { + Console.WriteLine("Connecting to the internet"); + } + + public virtual void AddApp(T app) + { + app.InstallApp(); + apps.Add(app); + } + + public void StartApp(T application) + { + foreach (T app in apps) + { + if (application.Equals(app)) + { + app.RunApp(); + return; + } + } + + Console.WriteLine($"No such application "); + } + } +} \ No newline at end of file diff --git a/CourseApp/Phones/Store.cs b/CourseApp/Phones/Store.cs new file mode 100644 index 0000000..4255813 --- /dev/null +++ b/CourseApp/Phones/Store.cs @@ -0,0 +1,29 @@ +namespace Phones +{ + using System; + + public class Store + { + private IDisplayable[] storage; + private int index; + + public Store() + { + storage = new IDisplayable[5]; + } + + public void AddItem(IDisplayable item) + { + storage[index] = item; + index++; + } + + public void Show() + { + for (int i = 0; i < index; i++) + { + Console.WriteLine($"item {i} {storage[i].Display()}"); + } + } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 030f047..3948781 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,26 +1,62 @@ namespace CourseApp { using System; + using Phones; public class Program { public static void Main(string[] args) { - Phone phone1 = new Phone("iPhone", -7); - phone1.Show(); - phone1.Diagonal = 7; - phone1.Show(); - phone1.Diagonal = -16; - phone1.Show(); - - Phone tablet = new Phone("Android", 6); - tablet.Diagonal = 6; - tablet.Show(); - tablet.Diagonal = -10; - tablet.Show(); - tablet.Diagonal = 8; - tablet.Show(); - Console.WriteLine("Hello World"); + Phone phone1 = new LandlinePhone("+7000000", "Проводной", -7); + var phone2 = phone1; + CellPhone cell1 = new CellPhone(); + cell1.Diagonal = 3; + cell1.Diagonal = -3; + Console.WriteLine(cell1); + Phone cell2 = new CellPhone("+90000", "ericson", 5); + Console.WriteLine(cell2); + + CellPhone cell3 = (CellPhone)cell2; + + CellPhone nokia = new CellPhone("+99999", "Nokia", 2000); + nokia.AcceptCall(); + nokia.CloseCall(); + nokia.TrackName = "AAAAAA very good song"; + nokia.PlayMusic(); + + Phone poly = new CellPhone("+876543", "MyPhone", 2000); + Console.WriteLine("-----------------"); + Console.WriteLine(poly); + + CellPhone cell = (CellPhone)poly; + + Console.WriteLine(poly); + + var smart = new SmartPhone(); + + var pen = new Pen(); + var store = new Store(); + store.AddItem(phone1); + store.AddItem(cell1); + store.AddItem(cell2); + store.AddItem(smart); + store.AddItem(pen); + Console.WriteLine("-------------------------"); + store.Show(); + Console.WriteLine("-------------------------"); + + var faceTime = new FaceTime("FaceTime"); + smart.AddApp(faceTime); + + smart.StartApp(faceTime); + Console.WriteLine("-------------------------"); + var pixel = new AndroidPhone("+77777", "GPixel", 2022); + var iphone = new IOSPhone("+78888888", "IPhone14", 2022); + + // Следующая строка не будет работать + // pixel.InstallApp(faceTime); + pixel.AddApp(new KeepApp("Keep")); + iphone.AddApp(faceTime); } } } diff --git a/README.md b/README.md index 2611643..4164784 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,36 @@ Finally you may work with migration (from `WebApplication` folder). The followin ``` dotnet ef migrations add InitialMigration ``` + +# Phones Store + +Существуют телефоны, которые могут осуществлять голосовой вызов, у них появляются методы - принять вызов, завершить вызов, позвонить. +Существуют сотовые телефоны, которые могут отправить сообщение, принять сообщение, отправить сообщение, а так сбросить вызов. +Существуют смартфоны (различающиеся операционной системой), определяются диагональю экрана, можно установить и запустить приложение +Все телефоны могут быть представлены в магазине. + +Phone: + Number {get; set;} + AcceptCall() + CloseCall() + MakeCall(phoneNumber) + + CellPhone: + PlayMusic() + SendMessage(number, message) + GetMessage() -> message + DeclineCall() + + Smarphone + Diagonal {get; set;} + OsType {get; set;} + ConnectToInternet() + InstallApp() + StartApp() + UninstallApp() + + Iphone14: + lidar() + Redmi14: + Wallet() + \ No newline at end of file