import java.util.Scanner;/**
*
* @author Administrator
*/
public class Fan { int SLOW = 1, MEDIUM = 2, FASE = 3;
private int speed = SLOW;
private boolean on = false;
private double radius = 5;
private String color = "blue"; public Fan() {
} public void setspeed(int s) {
this.speed = s;
} public void setstate(boolean a) {
this.on = a;
} public void setradius(double r) {
this.radius = r;
} public void setcolor(String b) {
this.color = b;
} public int getspeed() {
return speed;
} public boolean getstate() {
return on;
} public double getradius() {
return radius;
} public void toString(boolean on) {
if (on == true) {
System.out.println("Fan打开了; " + "Fan的半径: " + radius + "\n" + "速度:" + speed + "\n" + "颜色: " + color + "\n"); } else if (on == false) {
System.out.println("Fan被关闭了");
}
} public void choose1() {
Scanner input = new Scanner(System.in);
System.out.println("1.状态 2.风速 3.半径 4.颜色 5.退出");
int j = input.nextInt();
while (j != 5) {
if (j != 1 && j != 2 && j != 3 && j != 4) {
System.out.println("输入有误,请重新输入!!!");
} else if (j == 1) {
System.out.println("1.关闭风扇 2.打开风扇");
int k = input.nextInt();
if (k == 1) {
setstate(false);
} else {
setstate(true);
}
break;
} else if (j == 2) {
System.out.println("1.slow 2.middle 3.fast");
int k = input.nextInt();
if (k == 1) {
setspeed(1);
} else if (k == 2) {
setspeed(2);
} else {
setspeed(3);
}
break;
} else if (j == 3) {
System.out.println("输入半径");
int k = input.nextInt();
setradius(k);
break;
} else if (j == 4) {
System.out.println("输入颜色");
String m = input.toString();
setcolor(m);
break;
}
}
} public void choose2() {
boolean jan = getstate();
toString(jan);
} public static void main(String args[]) {
Fan application = new Fan();
int i;
System.out.println("------------------------------------------------------------");
System.out.println("1.更改Fan的属性 2.查看Fan的属性 3.退出");
System.out.println("------------------------------------------------------------");
Scanner input = new Scanner(System.in);
i = input.nextInt();
while (i != 3) {
if (i != 1 && i != 2) {
System.out.println("输入有误!");
} else if (i == 1) {
application.choose1();
} else if (i == 2) {
application.choose2();
}
System.out.println("------------------------------------------------------------");
System.out.println("1.更改Fan的属性 2.查看Fan的属性 3.退出");
System.out.println("------------------------------------------------------------");
System.out.println("再次选择");
i = input.nextInt();
}
System.out.println("感谢使用!");
}
}这里提示有错误。然后我点了继续运行不再提示,可是现在每次运行出错都不在提示直接运行了,现在该怎么做才能让java在出错时发错提示呢???
*
* @author Administrator
*/
public class Fan { int SLOW = 1, MEDIUM = 2, FASE = 3;
private int speed = SLOW;
private boolean on = false;
private double radius = 5;
private String color = "blue"; public Fan() {
} public void setspeed(int s) {
this.speed = s;
} public void setstate(boolean a) {
this.on = a;
} public void setradius(double r) {
this.radius = r;
} public void setcolor(String b) {
this.color = b;
} public int getspeed() {
return speed;
} public boolean getstate() {
return on;
} public double getradius() {
return radius;
} public void toString(boolean on) {
if (on == true) {
System.out.println("Fan打开了; " + "Fan的半径: " + radius + "\n" + "速度:" + speed + "\n" + "颜色: " + color + "\n"); } else if (on == false) {
System.out.println("Fan被关闭了");
}
} public void choose1() {
Scanner input = new Scanner(System.in);
System.out.println("1.状态 2.风速 3.半径 4.颜色 5.退出");
int j = input.nextInt();
while (j != 5) {
if (j != 1 && j != 2 && j != 3 && j != 4) {
System.out.println("输入有误,请重新输入!!!");
} else if (j == 1) {
System.out.println("1.关闭风扇 2.打开风扇");
int k = input.nextInt();
if (k == 1) {
setstate(false);
} else {
setstate(true);
}
break;
} else if (j == 2) {
System.out.println("1.slow 2.middle 3.fast");
int k = input.nextInt();
if (k == 1) {
setspeed(1);
} else if (k == 2) {
setspeed(2);
} else {
setspeed(3);
}
break;
} else if (j == 3) {
System.out.println("输入半径");
int k = input.nextInt();
setradius(k);
break;
} else if (j == 4) {
System.out.println("输入颜色");
String m = input.toString();
setcolor(m);
break;
}
}
} public void choose2() {
boolean jan = getstate();
toString(jan);
} public static void main(String args[]) {
Fan application = new Fan();
int i;
System.out.println("------------------------------------------------------------");
System.out.println("1.更改Fan的属性 2.查看Fan的属性 3.退出");
System.out.println("------------------------------------------------------------");
Scanner input = new Scanner(System.in);
i = input.nextInt();
while (i != 3) {
if (i != 1 && i != 2) {
System.out.println("输入有误!");
} else if (i == 1) {
application.choose1();
} else if (i == 2) {
application.choose2();
}
System.out.println("------------------------------------------------------------");
System.out.println("1.更改Fan的属性 2.查看Fan的属性 3.退出");
System.out.println("------------------------------------------------------------");
System.out.println("再次选择");
i = input.nextInt();
}
System.out.println("感谢使用!");
}
}这里提示有错误。然后我点了继续运行不再提示,可是现在每次运行出错都不在提示直接运行了,现在该怎么做才能让java在出错时发错提示呢???
解决方案 »
- 怎么读取配置文件app.properties中的信息
- Struts2.0中文API下载??
- 向JAVA技术高手提问,请指点
- 一道小JAVA题 请高手指点!!!!谢谢
- 基于spring,security,struts等框架写的开源项目(有图)
- 新建立的java 群希望大家参加 13003822
- 如何在客户程序中(如javaBean或jsp)访问EJB返回的结果集数据
- jbuilderx与tomcat配置的问题
- Unable to compile class for JSP:
- 怪事,劳烦各位朋友进来看看~
- 谁能帮我测试一下java ee。出错时我按钮继续运行,不再提示,结果现在有错误也不提示了。
- 电影网站如何嵌套百度播放器?
setcolor(m);
这里出错了, 写成input.nextLine(); 就ok了。