Advertisement
Guest User

hw07

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