Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace HW07_185221IABB
  6. {
  7.     interface IIron
  8.     {
  9.         void Descale();
  10.         void TurnOn();
  11.         void TurnOff();
  12.         void UseSteam();
  13.         void DoIroning();
  14.         void DoIroning(int temperature);
  15.         void DoIroning(string program);
  16.  
  17.     }
  18. }
  19.  
  20.  
  21.  
  22.  
  23. ______________________________________
  24.  
  25. using System;
  26. using System.Collections.Generic;
  27.  
  28. namespace HW07_185221IABB
  29. {
  30.     class Program
  31.     {
  32.         static void Main(string[] args)
  33.         {
  34.             RegularIron regular = new RegularIron();
  35.             regular.TurnOn();
  36.             regular.DoIroning();
  37.             regular.UseSteam();
  38.             regular.DoIroning();
  39.             regular.DoIroning();
  40.             Console.WriteLine();
  41.  
  42.             PremiumIron premium = new PremiumIron();
  43.             premium.TurnOn();
  44.             premium.DoIroning();
  45.             premium.UseSteam();
  46.             premium.DoIroning();
  47.             premium.UseSteam();
  48.             premium.DoIroning();
  49.             Console.WriteLine();
  50.  
  51.             LinenIron linen = new LinenIron();
  52.             linen.TurnOn();
  53.             linen.DoIroning();
  54.             linen.DoIroning(210);
  55.             linen.DoIroning(10);
  56.             linen.DoIroning("linen");
  57.             linen.DoIroning("linen");
  58.             linen.Descale();
  59.             linen.UseSteam();
  60.             linen.DoIroning();
  61.             linen.DoIroning();
  62.             linen.DoIroning("sportswear");
  63.         }
  64.     }
  65.  
  66.     class RegularIron : IIron
  67.     {
  68.         internal string _machineType;
  69.         internal bool _isOn;
  70.         internal int _uses;
  71.         internal int _minTemp;
  72.         internal int _maxTemp;
  73.         internal string _usesSteam;
  74.  
  75.         internal List<string> programs = new List<string>
  76.             {
  77.                 "synthetics", "silk", "cotton"
  78.             };
  79.  
  80.         public RegularIron()
  81.         {
  82.             _machineType = "Regular iron";
  83.             _isOn = false;
  84.             _uses = 0;
  85.             _minTemp = 90;
  86.             _maxTemp = 199;
  87.         }
  88.  
  89.         public void Descale()
  90.         {
  91.             if (_isOn)
  92.             {
  93.                 Console.WriteLine("Cleaned the machine!");
  94.                 _uses = 0;
  95.             }
  96.         }
  97.  
  98.         public void TurnOn()
  99.         {
  100.             if (_isOn == false)
  101.             {
  102.                 _isOn = true;
  103.             }
  104.             else
  105.             {
  106.                 Console.WriteLine("Machine is already on!");
  107.             }
  108.         }
  109.  
  110.         public void TurnOff()
  111.         {
  112.             if (_isOn)
  113.             {
  114.                 _isOn = false;
  115.             }
  116.             else
  117.             {
  118.                 Console.WriteLine("Machine is already off!");
  119.             }
  120.         }
  121.  
  122.         public virtual void UseSteam()
  123.         {
  124.             if (_usesSteam != "(with steam)")
  125.             {
  126.                 _usesSteam = "(with steam)";
  127.             }
  128.             else
  129.             {
  130.                 Console.WriteLine("Steam is already on");
  131.             }
  132.         }
  133.  
  134.         public virtual void DoIroning()
  135.         {
  136.             if (_uses <= 3)
  137.             {
  138.                 if (_isOn)
  139.                 {
  140.                     Console.WriteLine("{0} is ironing {1}",_machineType, _usesSteam);
  141.                     _uses++;
  142.                 }
  143.                 else
  144.                 {
  145.                     Console.WriteLine("You have to turn on the iron before you can use it");
  146.                 }
  147.             }
  148.             else
  149.             {
  150.                 Console.WriteLine("Machine has been used 3 times and needs cleaning");
  151.             }
  152.             _usesSteam = "";
  153.         }
  154.  
  155.         public virtual void DoIroning(string program)
  156.         {
  157.             if (_isOn)
  158.             {
  159.                 if (_uses <= 3)
  160.                 {
  161.                     if (programs.Contains(program))
  162.                     {
  163.                         if (program == ("cotton"))
  164.                         {
  165.                             Console.WriteLine("{0} is ironing with 164 degrees {1}",
  166.                                 _machineType, _usesSteam);
  167.                         }
  168.                         else if (program == ("silk"))
  169.                         {
  170.                             Console.WriteLine("{0} is ironing with 124 degrees {1}",
  171.                                 _machineType, _usesSteam);
  172.                         }
  173.                         else if (program == ("synthetics"))
  174.                         {
  175.                             Console.WriteLine("{0} is ironing with 101 degrees",
  176.                                 _machineType);
  177.                         }
  178.                         _uses++;
  179.                         _usesSteam = "";
  180.                     }
  181.                     else
  182.                     {
  183.                         Console.WriteLine("We don't have a program for ironing {0}", program);
  184.                     }
  185.                 }
  186.                 else
  187.                 {
  188.                     Console.WriteLine("Machine has been used 3 times and needs cleaning");
  189.                 }
  190.             }
  191.             else
  192.             {
  193.                 Console.WriteLine("You have to turn on the iron before you can use it");
  194.             }
  195.         }
  196.  
  197.         public virtual void DoIroning(int temperature)
  198.         {
  199.             if (_isOn)
  200.             {
  201.                 if (_uses <= 3)
  202.                 {
  203.                     if (temperature > _minTemp && temperature < _maxTemp)
  204.                     {
  205.                         if (temperature > 90 && temperature < 119)
  206.                         {
  207.                             Console.WriteLine("{0} is ironing with synthectics program");
  208.                         }
  209.                         else if (temperature > 120 && temperature < 149)
  210.                         {
  211.                             Console.WriteLine("{0} is ironing with silk program {1}",
  212.                                 _machineType, _usesSteam);
  213.                         }
  214.                         else if (temperature > 150 && temperature < 199)
  215.                         {
  216.                             Console.WriteLine("{0} is ironing with cotton program {1}",
  217.                                 _machineType, _usesSteam);
  218.                         }
  219.                         _uses++;
  220.                     }
  221.                     else
  222.                     {
  223.                         Console.WriteLine("Invalid temperature range for ironing");
  224.                     }
  225.                 }
  226.                 else
  227.                 {
  228.                     Console.WriteLine("Machine has been used 3 times and needs cleaning");
  229.                 }
  230.             }
  231.             else
  232.             {
  233.                 Console.WriteLine("You have to turn on the iron before you can use it");
  234.             }
  235.         }
  236.     }
  237.  
  238.     class PremiumIron : RegularIron
  239.     {
  240.         private int _steamUsed;
  241.  
  242.         public PremiumIron()
  243.         {
  244.             _steamUsed = 0;
  245.             _machineType = "Premium iron";
  246.         }
  247.  
  248.         public override void DoIroning()
  249.         {
  250.             base.DoIroning();
  251.             TurnLightOn();
  252.             if (_uses == 3)
  253.             {
  254.                 Descale();
  255.             }
  256.  
  257.         }
  258.  
  259.         public override void DoIroning(int temperature)
  260.         {
  261.             base.DoIroning(temperature);
  262.             TurnLightOn();
  263.             if (_uses == 3)
  264.             {
  265.                 Descale();
  266.             }
  267.         }
  268.  
  269.         public override void DoIroning(string program)
  270.         {
  271.             base.DoIroning(program);
  272.             TurnLightOn();
  273.             if (_uses == 3)
  274.             {
  275.                 Descale();
  276.             }
  277.         }
  278.  
  279.         private void TurnLightOn()
  280.         {
  281.             if (_steamUsed == 2)
  282.             {
  283.                 Console.WriteLine("LIGHT IS ON!");
  284.             }
  285.         }
  286.  
  287.         public override void UseSteam()
  288.         {
  289.             if (_usesSteam != "(with steam)")
  290.             {
  291.                 _usesSteam = "(with steam)";
  292.                 _steamUsed++;
  293.             }
  294.             else
  295.             {
  296.                 Console.WriteLine("Steam is already on");
  297.             }
  298.         }
  299.     }
  300.  
  301.     class LinenIron : RegularIron
  302.     {
  303.         public LinenIron()
  304.         {
  305.             _maxTemp = 230;
  306.             _machineType = "Linen iron";
  307.             programs.Add("linen");
  308.         }
  309.  
  310.         public override void DoIroning(int temperature)
  311.         {
  312.             base.DoIroning(temperature);
  313.             if (_uses <= 3)
  314.             {
  315.                 if (temperature > 200 && temperature < 230)
  316.                 {
  317.                     _usesSteam = "(with steam)";
  318.                     Console.WriteLine("{0} is ironing with linen program {1}",
  319.                         _machineType, _usesSteam);
  320.                 }
  321.                 _usesSteam = "";
  322.             }
  323.             else
  324.             {
  325.                 Console.WriteLine("Machine has been used 3 times and needs cleaning");
  326.             }
  327.         }
  328.  
  329.         public override void DoIroning(string program)
  330.         {
  331.             base.DoIroning(program);
  332.             if (_uses <= 3)
  333.             {
  334.                 if (program == "linen")
  335.                 {
  336.                     _usesSteam = "(with steam)";                    
  337.                     Console.WriteLine("{0} is ironing with 221 degrees {1}",
  338.                         _machineType, _usesSteam);
  339.                     _usesSteam = "";
  340.                 }
  341.             }
  342.             else
  343.             {
  344.                 Console.WriteLine("Machine has been used 3 times and needs cleaning");
  345.             }
  346.         }
  347.     }
  348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement