Advertisement
Guest User

Untitled

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