割り当て用のプログラムを作成していますが、defaultFanメソッドとtoStringメソッドで、「メソッド宣言が無効です。戻り型が必要です。ただし、これを解決する方法がわかりません。2つの前にvoidを付けてみました。メソッドとそれは機能しましたが、変数を最終変数に低速、中速、高速で割り当てることができないというエラーが表示されます。これが正しいかどうかわかりません。これを修正するにはどうすればよいですか。
また、テストプログラムを使用するのに苦労しています。私の教授は、2つのファンオブジェクトを作成するテストプログラムを使用することを望んでいます。最初に最大速度、半径10、黄色、およびオンのステータスを割り当てます。2つ目は、中速、半径5の色、青、オフのステータスを割り当て、toStringメソッドを呼び出してファンオブジェクトを表示します。誰かがテストプログラムがどのように機能するか、そして私がこのプログラムのためにそれを作成する方法を説明することは可能でしょうか?これが私のコードです:
public class fan {
private final int slow = 1;
private final int medium = 2;
private final int fast = 3;
private int speed;
private boolean fanOn;
private double radius;
private String color;
public void defaultFan( )
{
int speed = 1;
boolean fanOn = false;
double radius = 5;
String color = "blue";
}
public fan(final int slow, final int medium, final int fast, int
speed, boolean fanOn, double radius, String color) {
this.slow = slow;
this.medium = medium;
this.fast = fast;
this.speed = speed;
this.fanOn = fanOn;
this.radius = radius;
this.color = color;
}
public final int getSlow(){
return slow;
}
public final int getMedium() {
return medium;
}
public final int getFast() {
return fast;
}
public int getSpeed() {
return speed;
}
public boolean getfanOn() {
return fanOn;
}
public double getradius() {
return radius;
}
public String getcolor() {
return color;
}
public void setSlow(final int slow) {
this.slow = slow;
}
public void setMedium(final int medium) {
this.medium = medium;
}
public void setFast(final int fast) {
this.fast = fast;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public void setFanOn(boolean fanOn) {
this.fanOn = fanOn;
}
public void setRadius(double radius) {
this.radius = radius;
}
public void setColor(String color) {
this.color = color;
}
public void toString() {
if(fanOn = true ) {
System.out.println("The speed of the fan is " + speed + ", the color
of the the fan is " + color + ", and the radius of the fan is " +
radius + ".");
}
else {
System.out.println("The fan is off but the color is " + color +"
and the radius is " + radius + ".");
}
}}