번호 이외의 다른 출력을 읽을 일부 데이터 유형을 변경하려고 3. 나는 시험 수업에서 보내지거나 팬 클래스에서 사적인 것으로 옮겨 갈 수있는 변경 사항을 어디에서 만들 수 있는지 잘 모르겠습니다. toString에 몇 가지 호출을 추가하려고 시도했지만 16 진수 결과를 얻고 있습니다. 이 문제를 해결하기위한 여러 가지 방법이 도움이 될 것입니다.2 출력 내 속도에 대한 문자열 대신 1</p> <p>, 내가 출력 <code>toString</code>에 팬을 얻기 위해 어떤 종류의 캐스팅을 할 필요가 생각하고
public class Fan {
public final int SLOW = 1;
public final int MEDIUM = 2;
public final int FAST = 3;
private int speed; // = SLOW;
private boolean on; // on = false;
private double radius; // radius = 5;
private String color; // = "white";
public int getSpeed () {return speed; }
public void setSpeed (int speed) { this.speed = speed; }
public boolean isOn () {return on; }
public void setOn (boolean on) {this.on = on; }
public double getRadius () {return radius; }
public void setRadius (double radius) { this.radius = radius; }
public String getColor () { return color; }
public void setColor (String color) { this.color = color; }
public Fan () {
System.out.println("Default constructor called");
}
// default constructor
public Fan (int speed, boolean on, double radius, String color) {
this.speed = speed;
this.on = on;
this.radius = radius;
this.color = color;
System.out.println("Overloaded constructor called");
}
//overloaded constructor
public String toString() {
String x = "speed is " + speed + ", is the fan turned on? " + on + ",the radius "
+ "of the blades are " + radius + ", and the color of the fan is " + color;
return x;
}
}
public class FanTest {
public static void main(String[] args) {
Fan f1 = new Fan(3, true, 10, "Yellow") ;
Fan f2 = new Fan();
Fan f4 = new Fan();
f1.equals(f4) ;
Fan f3 = f1;
int slow = 1;
int medium = 2;
int fast = 3;
System.out.println(f1);
System.out.println(f2);
System.out.println(f3);
if (f1.equals(f3)) {
System.out.println("Obejects r3 and r1 are the same\n");
} else {
System.out.println("Objects r3 and r1 are different");
}
while (f1.equals(f4))
f4.setOn(false);
f4.setSpeed(2);
f4.setColor("green");
f4.setRadius(8);
System.out.println(f4);
}
}
같은를 반환 것을 의미한다. – Blakenblaze