Advertisement
Guest User

Untitled

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