/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package homework;/**
*
* @author Administrator
*/
/*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
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("感谢使用!");
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package homework;/**
*
* @author Administrator
*/
/*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
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中异常处理Exception类里面getLocalizedMessage和getMessage方法的区别什么
- hibernate-ExceptionInInitializerError几年了,问题依然!
- SCJP认证考试中的随机抽题如何实现?
- 【求助】关于JAVA小程序代码
- 5052365
- velocity的问题!!
- ResultSet 最大长度是多少??
- 本人最近做了一个spring+hibernate+ajax+jstl为主体的的开源后台管理与开发平台系统,有意者请进!
- 4折!!《J2EE构建企业级应用解决方案》
- Swagger2 ui参数排序问题
- request+response=?
- 一个很简单的java问题。
setcolor(m);
这里错了,应该是input.nextLine();