๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“œ ์ž๋ฐ” Java

์ž๋ฐ”(JAVA) - TV ์ „์›, ๋ณผ๋ฅจ, ์ฑ„๋„ ๋ฆฌ๋ชจ์ปจ ํ”„๋กœ๊ทธ๋ž˜๋ฐ

by Meteora_ 2021. 1. 26.
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

๋Œ“๊ธ€