Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace HW07_185221IABB
- {
- class Program
- {
- static void Main(string[] args)
- {
- RegularIron regular = new RegularIron();
- regular.TurnOn();
- regular.DoIroning();
- regular.UseSteam();
- regular.DoIroning();
- regular.DoIroning();
- Console.WriteLine();
- PremiumIron premium = new PremiumIron();
- premium.TurnOn();
- premium.DoIroning();
- premium.UseSteam();
- premium.DoIroning();
- premium.UseSteam();
- premium.DoIroning();
- Console.WriteLine();
- LinenIron linen = new LinenIron();
- linen.TurnOn();
- linen.DoIroning();
- linen.DoIroning(210);
- linen.DoIroning(10);
- linen.DoIroning("linen");
- linen.DoIroning("linen");
- linen.Descale();
- linen.UseSteam();
- linen.DoIroning();
- linen.DoIroning();
- linen.DoIroning("sportswear");
- }
- }
- class RegularIron : IIron
- {
- internal string _machineType;
- internal bool _isOn;
- internal int _uses;
- internal int _minTemp;
- internal int _maxTemp;
- internal string _usesSteam;
- internal List<string> programs = new List<string>
- {
- "synthetics", "silk", "cotton"
- };
- public RegularIron()
- {
- _machineType = "Regular iron";
- _isOn = false;
- _uses = 0;
- _minTemp = 90;
- _maxTemp = 199;
- }
- public void Descale()
- {
- if (_isOn)
- {
- Console.WriteLine("Cleaned the machine!");
- _uses = 0;
- }
- }
- public void TurnOn()
- {
- if (_isOn == false)
- {
- _isOn = true;
- }
- else
- {
- Console.WriteLine("Machine is already on!");
- }
- }
- public void TurnOff()
- {
- if (_isOn)
- {
- _isOn = false;
- }
- else
- {
- Console.WriteLine("Machine is already off!");
- }
- }
- public virtual void UseSteam()
- {
- if (_usesSteam != "(with steam)")
- {
- _usesSteam = "(with steam)";
- }
- else
- {
- Console.WriteLine("Steam is already on");
- }
- }
- public virtual void DoIroning()
- {
- if (_uses <= 3)
- {
- if (_isOn)
- {
- Console.WriteLine("{0} is ironing {1}",_machineType, _usesSteam);
- _uses++;
- }
- else
- {
- Console.WriteLine("You have to turn on the iron before you can use it");
- }
- }
- else
- {
- Console.WriteLine("Machine has been used 3 times and needs cleaning");
- }
- _usesSteam = "";
- }
- public virtual void DoIroning(string program)
- {
- if (_isOn)
- {
- if (_uses <= 3)
- {
- if (programs.Contains(program))
- {
- if (program == ("cotton"))
- {
- Console.WriteLine("{0} is ironing with 164 degrees {1}",
- _machineType, _usesSteam);
- }
- else if (program == ("silk"))
- {
- Console.WriteLine("{0} is ironing with 124 degrees {1}",
- _machineType, _usesSteam);
- }
- else if (program == ("synthetics"))
- {
- Console.WriteLine("{0} is ironing with 101 degrees",
- _machineType);
- }
- _uses++;
- _usesSteam = "";
- }
- else
- {
- Console.WriteLine("We don't have a program for ironing {0}", program);
- }
- }
- else
- {
- Console.WriteLine("Machine has been used 3 times and needs cleaning");
- }
- }
- else
- {
- Console.WriteLine("You have to turn on the iron before you can use it");
- }
- }
- public virtual void DoIroning(int temperature)
- {
- if (_isOn)
- {
- if (_uses <= 3)
- {
- if (temperature > _minTemp && temperature < _maxTemp)
- {
- if (temperature > 90 && temperature < 119)
- {
- Console.WriteLine("{0} is ironing with synthectics program");
- }
- else if (temperature > 120 && temperature < 149)
- {
- Console.WriteLine("{0} is ironing with silk program {1}",
- _machineType, _usesSteam);
- }
- else if (temperature > 150 && temperature < 199)
- {
- Console.WriteLine("{0} is ironing with cotton program {1}",
- _machineType, _usesSteam);
- }
- _uses++;
- }
- else
- {
- Console.WriteLine("Invalid temperature range for ironing");
- }
- }
- else
- {
- Console.WriteLine("Machine has been used 3 times and needs cleaning");
- }
- }
- else
- {
- Console.WriteLine("You have to turn on the iron before you can use it");
- }
- }
- }
- class PremiumIron : RegularIron
- {
- private int _steamUsed;
- public PremiumIron()
- {
- _steamUsed = 0;
- _machineType = "Premium iron";
- }
- public override void DoIroning()
- {
- base.DoIroning();
- TurnLightOn();
- if (_uses == 3)
- {
- Descale();
- }
- }
- public override void DoIroning(int temperature)
- {
- base.DoIroning(temperature);
- TurnLightOn();
- if (_uses == 3)
- {
- Descale();
- }
- }
- public override void DoIroning(string program)
- {
- base.DoIroning(program);
- TurnLightOn();
- if (_uses == 3)
- {
- Descale();
- }
- }
- private void TurnLightOn()
- {
- if (_steamUsed == 2)
- {
- Console.WriteLine("LIGHT IS ON!");
- }
- }
- public override void UseSteam()
- {
- if (_usesSteam != "(with steam)")
- {
- _usesSteam = "(with steam)";
- _steamUsed++;
- }
- else
- {
- Console.WriteLine("Steam is already on");
- }
- }
- }
- class LinenIron : RegularIron
- {
- public LinenIron()
- {
- _maxTemp = 230;
- _machineType = "Linen iron";
- programs.Add("linen");
- }
- public override void DoIroning(int temperature)
- {
- base.DoIroning(temperature);
- if (_uses <= 3)
- {
- if (temperature > 200 && temperature < 230)
- {
- _usesSteam = "(with steam)";
- Console.WriteLine("{0} is ironing with linen program {1}",
- _machineType, _usesSteam);
- }
- _usesSteam = "";
- }
- else
- {
- Console.WriteLine("Machine has been used 3 times and needs cleaning");
- }
- }
- public override void DoIroning(string program)
- {
- base.DoIroning(program);
- if (_uses <= 3)
- {
- if (program == "linen")
- {
- _usesSteam = "(with steam)";
- Console.WriteLine("{0} is ironing with 221 degrees {1}",
- _machineType, _usesSteam);
- _usesSteam = "";
- }
- }
- else
- {
- Console.WriteLine("Machine has been used 3 times and needs cleaning");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement