用java 设计一个空调遥控器
发布网友
发布时间:2022-06-30 14:34
我来回答
共2个回答
热心网友
时间:2023-10-15 19:13
import java.util.Scanner;
public class Test {
private int temperature = 26;
private boolean isOpen = false;
//1=开机,2=关机,3=升温,4=降温,5=显示。
public void start() {
isOpen = true;
System.out.println("开机。");
}
public void shutDown() {
if(!isOpen) {
System.out.println("还没有开机,请先开机");
return;
}
isOpen = false;
System.out.println("关机。");
}
public void temperatureRise() {
if(!isOpen) {
System.out.println("还没有开机,请先开机");
return;
}
temperature++;
System.out.println("温度上升。");
}
public void temperatureDown() {
if(!isOpen) {
System.out.println("还没有开机,请先开机");
return;
}
temperature--;
System.out.println("温度下降。");
}
public void show() {
System.out.println("空调遥控器:");
showTemperature();
System.out.println("--> 1=开机,2=关机,3=升温,4=降温,5=显示。0=退出系统");
}
public void showTemperature() {
System.out.println("当前温度:" + temperature + "℃");
}
public static void main(String[] args) {
Test test = new Test();
while(true) {
test.show();
Scanner scan = new Scanner(System.in);
int key = scan.nextInt();
if(key == 1)
test.start();
else if(key == 2)
test.shutDown();
else if(key == 3)
test.temperatureRise();
else if(key == 4)
test.temperatureDown();
else if(key == 5)
test.showTemperature();
else if(key == 0) {
System.out.println("退出系统");
break;
} else {
System.out.println("请按提示输入。");
}
}
}
}
热心网友
时间:2023-10-15 19:14
public class controler{
boolean on_off;
int temperature;
class Newframe extends Frame{
}