GiantStepDEV
article thumbnail

์ƒ์†๊ด€๊ณ„๊ฐ€ ์žˆ๋Š” TV
์˜ค๋ฒ„๋ผ์ด๋”ฉ ์ ์šฉ

Override : ๋ถ€๋ชจ ๋ฉ”์†Œ๋“œ์™€ ์™„๋ฒฝํ•˜๊ฒŒ ๊ฐ™์•„์•ผ ํ•จ. (๋ฐ˜ํ™˜ํƒ€์ž…/๋งค๊ฐœ๋ณ€์ˆ˜/์ ‘๊ทผ์ œํ•œ์ž)
package ์ƒ์†์ด์žˆ๋Š”TV0113;

public class InheritanceTV {
    public static void main(String[] args) {
        ProductTV lgTV = new ProductTV("์šฐ๋ฆฌ์ง‘ TV");
        lgTV.setPower(true);
        lgTV.setVolume(35);
        lgTV.setChannel(1000, true);
        lgTV.viewTV();
    }
}
package ์ƒ์†์ด์žˆ๋Š”TV0113;
// ProtoTypeTV๋Š” TV์˜ ๊ธฐ๋ณธ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง
public class ProtoTypeTV {
    protected boolean isPower; // ์ „์› ์„ค์ •๊ฐ’ ์ €์žฅ
    protected int channel; // ์ฑ„๋„ ์ •๋ณด ์ €์žฅ
    protected int volume; // ๋ณผ๋ฅจ ์ •๋ณด ์ €์žฅ

    public ProtoTypeTV() {
        this.isPower = false;
        channel = 10;
        volume = 10;
    }
    // ์ƒ์„ฑ์ž ์˜ค๋ฒ„๋กœ๋”ฉ ๋ฐœ์ƒ!
    public ProtoTypeTV(boolean isPower, int channel, int volume) {
        this.isPower = isPower;
        this.channel = channel;
        this.volume = volume;
    }
    public void setChannel(int cnl) {
        if(cnl > 0 && cnl < 1000) {
            channel = cnl;
        } else System.out.println("์ฑ„๋„ ์„ค์ • ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค.");
    }
}
class ProductTV extends ProtoTypeTV {
    private String name;
    private boolean isInternet;

    ProductTV() {
        super(true, 30, 30); // ๋ถ€๋ชจ์˜ ์ƒ์„ฑ์ž ํ˜ธ์ถœ
        name = "LG TV";
    }
    ProductTV(String name) {
        isPower = false;
        channel = 10;
        volume = 10;
        isInternet = false; // ๊ธฐ๋ณธ์ ์œผ๋กœ๋Š” ์ฑ„๋„ ์„ค์ • ๋ชจ๋“œ๋กœ ๋™์ž‘
        this.name = name;
    }
    void setPower(boolean power) {
        isPower = power;
        String OnOff = (isPower) ? "ON" : "OFF";
    }
    void setVolume(int vol) {
        if(vol >= 0 && vol <= 100) volume = vol;
        else System.out.print("๋ณผ๋ฅจ ์„ค์ • ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค.");
    }
    @Override
    public void setChannel(int cnl) {
        if(cnl > 0 && cnl < 2000) channel = cnl;
        else System.out.print("Error!!!");
    }
    // ๋ฉ”์†Œ๋“œ ์˜ค๋ฒ„๋กœ๋”ฉ
    public void setChannel(int cnl, boolean isInternet) {
        if(isInternet) {
            System.out.println("์ธํ„ฐ๋„ท ๋ชจ๋“œ ์ž…๋‹ˆ๋‹ค.");
            this.isInternet = true;
            String IntOnOff = (isInternet) ? "ON" : "OFF";
            } else System.out.println("error");
        }
    void viewTV() {
        String OnOff = (isPower) ? "ON" : "OFF";
        String IntOnOff = (isInternet) ? "ON" : "OFF";
        System.out.println("์ด๋ฆ„ : " + name);
        System.out.println("์ „์› : " + OnOff);
        System.out.println("์ฑ„๋„ : " + channel);
        System.out.println("๋ณผ๋ฅจ : " + volume);
        System.out.println("์ธํ„ฐ๋„ท ๋ชจ๋“œ : " + IntOnOff);
    }
}

profile

GiantStepDEV

@kongmi

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!