Java 기초

Java 기초 (연습하기-1)

Kw_w 2024. 3. 12. 11:46
“미루는 것은 쉬운 일을 어렵게 만들고 어려운 일을 더 어렵게 만든다.”
– 메이슨 쿨리

Q1.

삼성 에어컨을 20평형짜리를 1000원을 주고 구입했다. 해당 에어컨의 기본온도는 10도로 고정되어있고, 리모콘을 통해 에어컨을 on/off 할수 있고 해당 온도는 사용자의 명령에 따라 +1, -1도식 조절가능하다.

만약 에이컨 상태가 on 상태가 아니라면 온도조절을 할수없다. 또한 현재의 에어컨 상태를 표시할수 있어야 한다.

ex) 상태 출력예: 에어컨은 on 상태이고 현재온도는 12도이며, 삼성브랜드에 가격은 1000원

public class Aircon {
    int size;
    int price;
    String brand;
    int temp = 10;
    boolean power;

    public boolean power(){
        power = !power;
        return power;}
    public int upTemp(){return temp++;}
    public int downTemp(){return temp--;}
    public void setPrice(int price){this.price = price;}
    public void setSize(int size){this.size = size;}

    public void printFinfo(){System.out.println(power+", "+temp);}
}
class RemoteControl {
    Aircon aircon;
    public void setAircon(Aircon aircon){this.aircon = aircon;}
    public boolean power(){return aircon.power();}
    public int upTemp(){return aircon.upTemp();}
    public int downTemp(){return aircon.downTemp();}
}

class AppUIa{
    public static void main(String[] args) {
        Aircon aircon = new Aircon();
        RemoteControl remoteControl = new RemoteControl();
        remoteControl.setAircon(aircon);

        var power = remoteControl.power();
        if(power) System.out.println("power on");

        remoteControl.upTemp();
        remoteControl.upTemp();
        remoteControl.upTemp();
        remoteControl.downTemp();

        aircon.printFinfo();
    }
}