코드비교

Old VersionNew Version
1 1 
2class Fan1 { 2class Fan1 { 
3static final int SLOW=1; 3static int SLOW = 1;
4static final int MEDIUM=2; 4static int MEDIUM = 2;
5static final int FAST=3; 5static int FAST = 3;
6int speed; 6int speed; 
7boolean on; 7boolean on; 
8double radius; 8double radius; 
9String color; 9String color; 
  10void setSpeed(int speed) { 
  11this.speed = speed; 
  12} 
  13void setOn(boolean on) { 
  14this.on = on; 
  15} 
  16void setRadius(double radius) { 
  17this.radius = radius; 
  18} 
  19void setColor(String color) { 
  20this.color = color; 
  21} 
  22int getSpeed() { 
  23return speed; 
  24} 
  25boolean getOn() { 
  26return on; 
  27} 
  28double getRadius() { 
  29return radius; 
  30} 
  31String getColor() { 
  32return color; 
  33} 
10Fan1() { 34Fan1() { 
11this.setSpeed(SLOW); 11speed = SLOW;
12on = false; 36on = false; 
13radius = 5; 37radius = 5; 
14color = "blue"; 38color = "blue"; 
15} 39} 
16void setSpeed(int a) {   
17if(a==1)   
18this.speed=1;   
19else if(a==2)   
20this.speed=2;   
21else   
22this.speed=3;   
23}   
24void setOn(boolean a) {   
25this.on=a;   
26}   
27void setRadius(double a) {   
28this.radius=a;   
29}   
30void setColor(String a) {   
31this.color=a;   
32}   
33int getSpeed() {   
34return this.speed;   
35}   
36boolean getOn() {   
37return this.on;   
38}   
39double getRadius() {   
40return this.radius;   
41}   
42String getColor() {   
43return this.color;   
44}   
45public String toString() { 40public String toString() { 
46if(this.on==true) 46if(on == false) {
47return "speed " + this.speed + "\ncolor " + this.color + "\nradius " + String.format("%.2f",this.radius); 47return "color " + color +"\n" + "radius " + String.format("%.2f", radius) + "\n" + "fan is off";
48else 48}else {
49return "color " + this.color + "\nradius " + String.format("%.2f",this.radius) 49return "speed " + speed +"\n" + "color " + color +"\n" + "radius " + String.format("%.2f", radius);
50+"\nfan is off";   
51} 45} 
52} 46} 
  47} 

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());
}
}
class Fan1 {
static final int SLOW=1;
static final int MEDIUM=2;
static final int FAST=3;
int speed;
boolean on;
double radius;
String color;
Fan1() {
this.setSpeed(SLOW);
on = false;
radius = 5;
color = "blue";
}
void setSpeed(int a) {
if(a==1)
this.speed=1;
else if(a==2)
this.speed=2;
else
this.speed=3;
}
void setOn(boolean a) {
this.on=a;
}
void setRadius(double a) {
this.radius=a;
}
void setColor(String a) {
this.color=a;
}
int getSpeed() {
return this.speed;
}
boolean getOn() {
return this.on;
}
double getRadius() {
return this.radius;
}
String getColor() {
return this.color;
}
public String toString() {
if(this.on==true)
return "speed " + this.speed + "\ncolor " + this.color + "\nradius " + String.format("%.2f",this.radius);
else
return "color " + this.color + "\nradius " + String.format("%.2f",this.radius)
+"\nfan is off";
}
}
class Fan1 {
static int SLOW = 1;
static int MEDIUM = 2;
static int FAST = 3;
int speed;
boolean on;
double radius;
String color;
void setSpeed(int speed) {
this.speed = speed;
}
void setOn(boolean on) {
this.on = on;
}
void setRadius(double radius) {
this.radius = radius;
}
void setColor(String color) {
this.color = color;
}
int getSpeed() {
return speed;
}
boolean getOn() {
return on;
}
double getRadius() {
return radius;
}
String getColor() {
return color;
}
Fan1() {
speed = SLOW;
on = false;
radius = 5;
color = "blue";
}
public String toString() {
if(on == false) {
return "color " + color +"\n" + "radius " + String.format("%.2f", radius) + "\n" + "fan is off";
}else {
return "speed " + speed +"\n" + "color " + color +"\n" + "radius " + String.format("%.2f", radius);
}
}
}