본문 바로가기

Java

Day05 - 4

public class Samsungfan {   //프라이빗 접근불가 현재 클래스의{} 바깥쪽에서는 절대 접근하거나 호출할 수 없음, 그래서 접근하기위해 객체를찍어서 불러온다??
        private static int serialnumber; //시리얼번호
        private String name; // 선풍기품명("SSEDA"+색상+시리얼번호)
        private String color; //선풍기색상
        private String rotation; //회전여부(기본값:고정)
        private int level;//강도(기본값:1,max:3)
        private String power; //전원여부(기본값:off)

    Samsungfan(){                       //빈 생성자를 출력하면 color white가 출력
           this("white");}           //기본생성자???


    Samsungfan(String color){           //생성자만든것
        this.power="off";
        this.rotation="고정";
        this.level=1;
        this.serialnumber+=1;
        this.color=color;
        this.name="SSEDA"+this.color+this.serialnumber;     ///????
    }

    public void rotation(){  //회전기능
        if(power.equals("on")){                     //power 변수가 "on"이면
            if(this.rotation=="고정"){                //여기 클래스내 rotation변수가 "고정"이면
                System.out.println("회전");           //회전으로 출력
                this.rotation="회전중";                //클래스내 rotaiton은 "회전중"으로저장한다
            }else{                              //그렇지않으면
                System.out.println("고정");            //고정이라고 출력
                this.rotation="고정";                 //클래스내 rotation변수는 "고정"으로 저장
            }
        }else{                                      //그렇지않으면
            System.out.println("전원이 꺼져있습니다");       //전원꺼짐상태를 출력
        }
    }

    public void power(){
        if(power.equals("off")){
            System.out.println("전원을 켜겠습니다");
            this.power="on";
        }else{
            System.out.println("전원을 끄겠습니다");
            this.level=1;
            this.rotation="고정";
            this.power="off";
        }
    }

    public void levelup(){
        if(this.power.equals("on")){
            if(this.level<3){                                   //up 2              3--->x
                this.level+=1;                                  //--->3                 x
                System.out.println(this.level+"단!");            //---->3단               x
            }else{
                System.out.println("3단!");                                              //o
            }
        }else{
            System.out.println("전원이 꺼져있습니다");
        }
    }

    public void leveldown(){
        if(this.power.equals("on")){
            if(this.level>1){
                this.level-=1;
                System.out.println(this.level+"단!");
            }else{
                System.out.println("1단!");
            }
        }else{
            System.out.println("전원이 꺼져있습니다");
        }
    }

    //게터세터          set 값을 설정 get 값을 저장

    public static int getSerialnumber() {
        return serialnumber;
    }

    public static void setSerialnumber(int serialnumber) {
        Samsungfan.serialnumber = serialnumber;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getRotation() {
        return rotation;
    }

    public void setRotation(String rotation) {
        this.rotation = rotation;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getPower() {
        return power;
    }

    public void setPower(String power) {
        this.power = power;
    }
    public void info(){
        System.out.println("현재 전원 : "+getPower()+"\n현재 바람세기 : "+getLevel() +
                "\n현재 회전여부 : " + getRotation() + "\n시리얼넘버 : "+getName()+
                "\n선풍기 색상 : "+ getColor());

    }
}

'Java' 카테고리의 다른 글

Day06 - 01  (0) 2023.02.01
Day06  (0) 2023.02.01
Day5 - 03  (0) 2023.01.29
Day5 - 01(Method)  (0) 2023.01.29
Day5  (0) 2023.01.29