코드비교

Old VersionNew Version
3static final int SLOW=1; 3static final int SLOW=1; 
4static final int MEDIUM=2; 4static final int MEDIUM=2; 
5static final int FAST=3; 5static final int FAST=3; 
  6private static boolean on=false; 
6private static int speed=SLOW; 7private static int speed=SLOW; 
7private static boolean on=false; 7private static double rad=5.00;
8private static double radius=5.00;   
9private static String color="blue"; 9private static String color="blue"; 
10Fan1(int speed1,boolean onoff1,double radius1,String x) { 10Fan1(boolean on_off,double radius,int velocity, String col) {
11speed=speed1; 11speed=velocity;
12on=onoff1; 12on=on_off;
13radius=radius1; 13rad=radius;
14color=x; 14color=col;
15} 15} 
16Fan1() {} 16Fan1() {} 
17public static void setSpeed(int speed) { 17public static void setOn(boolean on_off) { Fan1.on = on_off; }
18Fan1.speed = speed; 18public static void setRadius(double radius) { Fan1.rad = radius; }
19} 19public static void setSpeed(int v) { Fan1.speed = v; }
20public static void setColor(String color) { 20public static void setColor(String col) { Fan1.color = col; }
21Fan1.color = color;   
22}   
23public static void setRadius(double radius) {   
24Fan1.radius = radius;   
25}   
26public static void setOn(boolean on) {   
27Fan1.on = on;   
28}   
29public String toString() { 21public String toString() { 
30String k=String.format("%.2f", radius); 30String res="";
31String x="";   
32if (on) { 23if (on) { 
33x+="speed "+speed; 33res+="speed "+speed; res+="\n";
34x+="\n"; 34res+="color "+color; res+="\n";
35x+="color "+color; 35String rad_to_str=String.format("%.2f", rad);
36x+="\n"; 36res+="radius "+rad_to_str;
37x+="radius "+k; 37return res;
38return x;   
39} 29} 
40else { 30else { 
41x+="color "+color; 41res+="color "+color;   res+="\n";
42x+="\n"; 42String rad_to_str=String.format("%.2f", rad);
43x+="radius "+k; 43res+="radius "+rad_to_str; res+="\n";
44x+="\n"; 44res+="fan is off";
45x+="fan is off"; 45return res;
46return x;   
47} 36} 
48} 37} 
49} 38} 

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;
private static int speed=SLOW;
private static boolean on=false;
private static double radius=5.00;
private static String color="blue";
Fan1(int speed1,boolean onoff1,double radius1,String x) {
speed=speed1;
on=onoff1;
radius=radius1;
color=x;
}
Fan1() {}
public static void setSpeed(int speed) {
Fan1.speed = speed;
}
public static void setColor(String color) {
Fan1.color = color;
}
public static void setRadius(double radius) {
Fan1.radius = radius;
}
public static void setOn(boolean on) {
Fan1.on = on;
}
public String toString() {
String k=String.format("%.2f", radius);
String x="";
if (on) {
x+="speed "+speed;
x+="\n";
x+="color "+color;
x+="\n";
x+="radius "+k;
return x;
}
else {
x+="color "+color;
x+="\n";
x+="radius "+k;
x+="\n";
x+="fan is off";
return x;
}
}
}
class Fan1 {
static final int SLOW=1;
static final int MEDIUM=2;
static final int FAST=3;
private static boolean on=false;
private static int speed=SLOW;
private static double rad=5.00;
private static String color="blue";
Fan1(boolean on_off,double radius,int velocity, String col) {
speed=velocity;
on=on_off;
rad=radius;
color=col;
}
Fan1() {}
public static void setOn(boolean on_off) { Fan1.on = on_off; }
public static void setRadius(double radius) { Fan1.rad = radius; }
public static void setSpeed(int v) { Fan1.speed = v; }
public static void setColor(String col) { Fan1.color = col; }
public String toString() {
String res="";
if (on) {
res+="speed "+speed;  res+="\n";
res+="color "+color;  res+="\n";
String rad_to_str=String.format("%.2f", rad);
res+="radius "+rad_to_str;
return res;
}
else {
res+="color "+color;    res+="\n";
String rad_to_str=String.format("%.2f", rad);
res+="radius "+rad_to_str;  res+="\n";
res+="fan is off";
return res;
}
}
}