Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.7 kB
4
Indexable
Never
main(){
	Ovladac ovladacVObyvaku = new Ovladac();
	Televize samsungL550Smart = new Televize();
	ovladacVObyvaku.Sparuj(samsungL550Smart);
	ovladacVObyvaku.TlacitkoPowerZmacknuto();
	ovladacVObyvaku. TlacitkoVolumeUpZmacknuto();
}

public class Ovladac{
	public string vyrobce;
	public IZarizeni sparovaneZarizeni;
	
	public Ovladac(string vyrobce){
		this.vyrobce = vyrobce;
	}
	
	public void Sparuj(IZarizeni zarizeni){
		this.sparovaneZarizeni = zarizeni
	}
	
	public void TlacitkoVolumeUpZmacknuto(){
		this.sparovaneZarizeni.zmenVolume(1);
	}
	public void TlacitkoVolumeDownZmacknuto(){
		this.sparovaneZarizeni.zmenVolume(-1);
	}
	public void TlacitkoPowerZmacknuto(){
		this.sparovaneZarizeni.zmenStav();
	}
	
}

public interface IZarizeni{
	public void zmenStav();
	public void zmenVolume(int oKolik);
	public void prepnoutKanal(int cisloKanalu);
}

public class Televize: IZarizeni{
	public int volume;
	public int kanal;
	public bool zapnuto;
	
	public Televize(){
		this.volume = 0;
		this.kanal = 0;
		this.zapnuto = false;
	}
	
	public void zmenStav(){
		if (this.zapnuto == false){
			this.zapnuto = true;
			Console.WriteLine("Televize byla zapnuta");
		} else {
			this.zapnuto = false
			Console.WriteLine("Televize byla vypnuta");
		}
	}
	
	public void zmenVolume(int oKolik){
		this.volume += oKolik;
		if (this.volume < 0){
			this.volume = 0
		}
		if (this.volume > 100){
			this.volume = 100
		}
		Console.WriteLine("Aktulni hlasitost je", this.volume);
	}
	
	public void prepnoutKanal(int cisloKanalu){
		this.kanal = cisloKanalu;
		Console.WriteLine("Aktulni kanal je", this.kanal);
	}
}
Leave a Comment