Advertisement
Guest User

hw07

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