코드비교

Old VersionNew Version
3final static int SLOW = 1; 3final static int SLOW = 1; 
4final static int MEDIUM = 2; 4final static int MEDIUM = 2; 
5final static int FAST = 3; 5final static int FAST = 3; 
6private int speed = SLOW; 6private int speed;
7private boolean on = false; 7private boolean on ;
8private double radius = 5; 8private double radius;
9String color = "blue"; 9private String color;
   10public Fan1() {
   11speed=SLOW;
   12on = false;
   13radius =5.00;
   14color="blue";
   15}
10public int getSpeed() { 16public int getSpeed() { 
11return speed; 17return speed; 
12} 18} 
13public boolean isOn() { 13public boolean getOn() {
14return on; 20return on; 
15} 21} 
16public double getRadius() { 22public double getRadius() { 
17return (int)(radius * 100) / 100.0; 17return radius;
18} 24} 
19public String getColor() { 25public String getColor() { 
20return color; 26return color; 
21} 27} 
22public void setSpeed(int speed) { 22public void setSpeed(int a) {
23this.speed = speed; 23speed=a;
24} 30} 
25public void setOn(boolean on) { 25public void setRadius(double r) {
26this.on = on; 26radius=r;
27} 33} 
28public void setRadius(double radius) { 28public void setColor(String c) {
29this.radius = radius; 29color=c;
30} 36} 
31public void setColor(String color) { 31public void setOn(boolean o) {
32this.color = color; 32on=o;
33} 39} 
34public String toString() { 40public String toString() { 
35if(on) 35if(on==true) {
36return "speed " + speed + "\ncolor " + color + "\nradius " + String.format("%.2f", radius); 36return "speed ".concat(String.format("%d",speed)).concat("\ncolor ").concat(String.format("%s",color)).concat("\nradius ").concat(String.format("%.2f",radius));
37else 37}else {
38return "color " + color + "\nradius " + String.format("%.2f", radius) + "\nfan is off"; 38return "color ".concat(String.format("%s",color)).concat("\nradius ").concat(String.format("%.2f",radius)).concat("\nfan is off");
39} 45} 
40} 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 {
final static int SLOW = 1;
final static int MEDIUM = 2;
final static int FAST = 3;
private int speed = SLOW;
private boolean on = false;
private double radius = 5;
String color = "blue";
public int getSpeed() {
return speed;
}
public boolean isOn() {
return on;
}
public double getRadius() {
return (int)(radius * 100) / 100.0;
}
public String getColor() {
return color;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public void setOn(boolean on) {
this.on = on;
}
public void setRadius(double radius) {
this.radius = radius;
}
public void setColor(String color) {
this.color = color;
}
public String toString() {
if(on)
return "speed " + speed + "\ncolor " + color + "\nradius " + String.format("%.2f", radius);
else
return "color " + color + "\nradius " + String.format("%.2f", radius) + "\nfan is off";
}
}
class Fan1 {
final static int SLOW=1;
final static int MEDIUM=2;
final static int FAST=3;
private int speed;
private boolean on ;
private double radius;
private String color;
public Fan1() {
speed=SLOW;
on = false;
radius =5.00;
color="blue";
}
public int getSpeed() {
return speed;
}
public boolean getOn() {
return on;
}
public double getRadius() {
return radius;
}
public String getColor() {
return color;
}
public void setSpeed(int a) {
speed=a;
}
public void setRadius(double r) {
radius=r;
}
public void setColor(String c) {
color=c;
}
public void setOn(boolean o) {
on=o;
}
public String toString() {
if(on==true) {
return "speed ".concat(String.format("%d",speed)).concat("\ncolor ").concat(String.format("%s",color)).concat("\nradius ").concat(String.format("%.2f",radius));
}else {
return  "color ".concat(String.format("%s",color)).concat("\nradius ").concat(String.format("%.2f",radius)).concat("\nfan is off");
}
}
}