我有 2 个分类在不同的页面。
对象类:
public class Sensor {
Type type;
public static enum Type
{
PROX,SONAR,INF,CAMERA,TEMP;
}
public Sensor(Type type)
{
this.type=type;
}
public void TellIt()
{
switch(type)
{
case PROX:
System.out.println("The type of sensor is Proximity");
break;
case SONAR:
System.out.println("The type of sensor is Sonar");
break;
case INF:
System.out.println("The type of sensor is Infrared");
break;
case CAMERA:
System.out.println("The type of sensor is Camera");
break;
case TEMP:
System.out.println("The type of sensor is Temperature");
break;
}
}
public static void main(String[] args)
{
Sensor sun=new Sensor(Type.CAMERA);
sun.TellIt();
}
}
主类:
import Sensor.Type;
public class MainClass {
public static void main(String[] args)
{
Sensor sun=new Sensor(Type.SONAR);
sun.TellIt();
}
错误有两种,一种是无法解析类型,另一种是无法导入。我能做些什么?我第一次使用枚举,但你看。