4400 - Fan1 클래스

Time Limit: 1s Memory Limit: 128MB

Snippet Judge Submissions: 1429 Solved: 440
Description

다음 특징을 가지는 Fan1 클래스를 만들기 바랍니다.

  • 선풍기 속도를 나타내는 상수 SLOW, MEDIUM, FAST를 가지고, 그 값은 각각 1, 2, 3이다.
  • 선풍기의 속도를 나타내는 int형의 speed 필드를 가진다. (기본은 SLOW)
  • 선풍기 전원의 상태를 나타내는 boolean형의 on 필드를 가진다. (기본은 false)
  • 선풍기의 반지름을 나타내는 double형의 radius 필드를 가진다. (기본은 5)
  • 선풍기의 색상을 나타내는 string형의 color 필드를 가진다. (기본은 blue)
  • 모든 데이터 필드에 대한 accessor 메소드와 mutator 메소드를 가진다.
  • 기본값의 가지고 있는 선풍기를 생성하는 무(無)인자(no-arg) 생성자를 가진다.
  • 선풍기의 특징을 반환하는 toString() 메소드를 가진다. 만약 선풍기가 켜져있다면 이 메소드는 선풍기의 속도, 색상, 반지름을 하나의 string으로 반환한다. 선풍기가 꺼져있다면, 선풍기의 색상, 반지름과 "fan is off"라는 string을 하나의 string으로 반환한다.

The class contains:

  • Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed.
  • A private int data field named speed that specifies the speed of the fan (the default is SLOW).
  • A private boolean data field named on that specifies whether the fan is on (the default is false).
  • A private double data field named radius that specifies the radius of the fan (the default is 5).
  • A string data field named color that specifies the color of the fan (the default is blue).
  • The accessor and mutator methods for all four data fields.
  • A no-arg constructor that creates a default fan.
  • A method named toString() that returns a string description for the fan. If the fan is on, the method returns the fan speed, color, and radius in one combined string. If the fan is not on, the method returns the fan color and radius along with the string “fan is off” in one combined string.
Input

샘플 코드 참조

Output

샘플 코드 참조

- 실수형은 소수점 둘째자리로 반올림

Sample Code
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        Fan1 fan1 = new Fan1();
        for (int i = 0; i < n; i++) {
            String op = sc.next();
            String val = sc.next();
            if (op.compareTo("speed") == 0) {
                if (val.compareTo("SLOW") == 0) fan1.setSpeed(Fan1.SLOW);
                else if (val.compareTo("FAST") == 0) fan1.setSpeed(Fan1.FAST);
                else fan1.setSpeed(Fan1.MEDIUM);
            } else if (op.compareTo("radius") == 0) {
                fan1.setRadius(Double.parseDouble(val));
            } else if (op.compareTo("color") == 0) {
                fan1.setColor(val);
            } else if (op.compareTo("on") == 0) {
                if (val.compareTo("true") == 0) fan1.setOn(true);
                else fan1.setOn(false);
            }
        }
        System.out.println(fan1.toString());
    }
}

YOUR_CODE
Sample Input
2
speed FAST
on true
Sample Output
speed 3
color blue
radius 5.00
Source

JAVA2015 PE9.8