Advertisement
Guest User

H2w07

a guest
Oct 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.50 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.             premium.DoIroning();
  26.             Console.WriteLine();
  27.  
  28.             LinenIron linen = new LinenIron();
  29.             linen.TurnOn();
  30.             linen.DoIroning();
  31.             linen.DoIroning(210);
  32.             linen.DoIroning(10);
  33.             linen.DoIroning("linen");
  34.             linen.DoIroning("linen");
  35.             linen.Descale();
  36.             linen.UseSteam();
  37.             linen.DoIroning();
  38.             linen.DoIroning();
  39.             linen.DoIroning("sportswear");
  40.             linen.DoIroning("linen");
  41.             linen.DoIroning("linen");
  42.             linen.DoIroning("linen");
  43.         }
  44.     }
  45.  
  46.     class RegularIron : IIron
  47.     {
  48.         internal string _machineType;
  49.         internal bool _isOn;
  50.         internal int _uses;
  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.                 if (_isOn)
  119.                 {
  120.                     Console.WriteLine("{0} is ironing {1}", _machineType, _usesSteam);
  121.                     _uses++;
  122.                 }
  123.                 else
  124.                 {
  125.                     Console.WriteLine("You have to turn on the iron before you can use it");
  126.                 }
  127.             }
  128.             else
  129.             {
  130.                 Console.WriteLine("Machine has been used 3 times and needs cleaning");
  131.             }
  132.             _usesSteam = "";
  133.         }
  134.  
  135.         public virtual void DoIroning(string program)
  136.         {
  137.             if (_isOn)
  138.             {
  139.                 if (_uses <= 3)
  140.                 {
  141.                     if (programs.Contains(program))
  142.                     {
  143.                         if (program == ("cotton"))
  144.                         {
  145.                             Console.WriteLine("{0} is ironing with 164 degrees {1}",
  146.                                 _machineType, _usesSteam);
  147.                         }
  148.                         else if (program == ("silk"))
  149.                         {
  150.                             Console.WriteLine("{0} is ironing with 124 degrees {1}",
  151.                                 _machineType, _usesSteam);
  152.                         }
  153.                         else if (program == ("synthetics"))
  154.                         {
  155.                             Console.WriteLine("{0} is ironing with 101 degrees",
  156.                                 _machineType);
  157.                         }
  158.                         _uses++;
  159.                         _usesSteam = "";
  160.                     }
  161.                     else
  162.                     {
  163.                         Console.WriteLine("We don't have a program for ironing {0}", 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.  
  180.             if (_isOn)
  181.             {
  182.                 if (_uses <= 3)
  183.                 {
  184.                     if (temperature > _minTemp && temperature < _maxTemp)
  185.                     {
  186.                         if (temperature > 90 && temperature < 119)
  187.                         {
  188.                             Console.WriteLine("{0} is ironing with synthectics program");
  189.                         }
  190.                         else if (temperature > 120 && temperature < 149)
  191.                         {
  192.                             Console.WriteLine("{0} is ironing with silk program {1}",
  193.                                 _machineType, _usesSteam);
  194.                         }
  195.                         else if (temperature > 150 && temperature < 199)
  196.                         {
  197.                             Console.WriteLine("{0} is ironing with cotton program {1}",
  198.                                 _machineType, _usesSteam);
  199.                         }
  200.                         _uses++;
  201.                     }
  202.                     else
  203.                     {
  204.                         Console.WriteLine("Invalid temperature range for ironing");
  205.                     }
  206.                 }
  207.                 else
  208.                 {
  209.                     Console.WriteLine("Machine has been used 3 times and needs cleaning");
  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.  
  220.     class PremiumIron : RegularIron
  221.     {
  222.         private int _steamUsed;
  223.  
  224.         public PremiumIron()
  225.         {
  226.             _steamUsed = 0;
  227.             _machineType = "Premium iron";
  228.         }
  229.  
  230.         public override void DoIroning()
  231.         {
  232.             base.DoIroning();
  233.             if (_steamUsed == 2)
  234.             {
  235.                 Console.WriteLine("LIGHT IS ON!");
  236.             }
  237.             if (_uses == 3)
  238.             {
  239.                 Descale();
  240.             }
  241.            
  242.         }
  243.  
  244.         public override void DoIroning(int temperature)
  245.         {
  246.             base.DoIroning(temperature);
  247.             if (_steamUsed == 2)
  248.             {
  249.                 Console.WriteLine("LIGHT IS ON!");
  250.             }
  251.             if (_uses == 3)
  252.             {
  253.                 Descale();
  254.             }
  255.         }
  256.  
  257.         public override void DoIroning(string program)
  258.         {
  259.             base.DoIroning(program);
  260.             if (_steamUsed == 2)
  261.             {
  262.                 Console.WriteLine("LIGHT IS ON!");
  263.             }
  264.             if (_uses == 3)
  265.             {
  266.                 Descale();
  267.             }
  268.         }
  269.  
  270.         public override void UseSteam()
  271.         {
  272.             if (_usesSteam != "(with steam)")
  273.             {
  274.                 _usesSteam = "(with steam)";
  275.                 _steamUsed++;
  276.  
  277.                
  278.             }
  279.             else
  280.             {
  281.                 Console.WriteLine("Steam is already on");
  282.             }
  283.  
  284.         }
  285.     }
  286.  
  287.     class LinenIron : RegularIron
  288.     {
  289.         public LinenIron()
  290.         {
  291.             _maxTemp = 230;
  292.             _machineType = "Linen iron";
  293.             programs.Add("linen");
  294.         }
  295.  
  296.         public override void DoIroning(int temperature)
  297.         {
  298.             base.DoIroning(temperature);
  299.             if (_uses <= 3)
  300.             {
  301.                 if (temperature > 200 && temperature < 230)
  302.                 {
  303.                     _usesSteam = "(with steam)";
  304.                     _uses++;
  305.                     Console.WriteLine("{0} is ironing with linen program {1}",
  306.                         _machineType, _usesSteam);
  307.                 }
  308.                 _usesSteam = "";
  309.             }
  310.             else
  311.             {
  312.                 Console.WriteLine("Can't iron because machine needs cleaning!");
  313.             }
  314.        
  315.         }
  316.  
  317.         public override void DoIroning(string program)
  318.         {
  319.             if (_uses <= 3)
  320.             {
  321.                 base.DoIroning(program);
  322.                 if (program == "linen")
  323.                 {
  324.                     _usesSteam = "(with steam)";
  325.                     _uses++;
  326.                     Console.WriteLine("{0} is ironing with 221 degrees {1}",
  327.                         _machineType, _usesSteam);
  328.                     _usesSteam = "";
  329.                 }
  330.             }
  331.             else
  332.             {
  333.                 Console.WriteLine("Can't iron because machine needs cleaning!");
  334.             }
  335.  
  336.         }
  337.     }
  338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement