📜 자바 Java
자바(JAVA) - TV 전원, 볼륨, 채널 리모컨 프로그래밍
Meteora_
2021. 1. 26. 16:22
728x90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public class MainClass { public static void main(String[] args) { Mytv2 t = new Mytv2(); t.setChannel(10); System.out.println("CH:" + t.getChannel()); t.setVolume(20); System.out.println("VOL" + t.getVolume()); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | public class Mytv2 { private boolean isPowerOn; private int channel; private int volume; final int MAX_VOLUME = 100; final int MIN_VOLUME = 0; final int MAX_CHANNEL = 100; final int MIN_CHANNEL = 1; void serPowerOn(boolean isPowerOn) { this.isPowerOn = isPowerOn; } boolean getPowerOn() { return isPowerOn; } void setChannel(int channel) { if(!(channel>MAX_CHANNEL || channel < MIN_CHANNEL)) this.channel = channel; } int getChannel() { return channel; } void setVolume(int volume) { if(!(volume > MAX_VOLUME || volume < MIN_VOLUME )) this.volume = volume; } int getVolume() { return volume; } } | cs |