「java空调」空调提供jdk安装是什么意思
本篇文章给大家谈谈java空调,以及空调提供jdk安装是什么意思对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
用Java语言实现空调的风速的控制代码怎么写?
/**
*@param i 调档
*1.低档 2.中档 3.高档
*/
public void test(int i){
switch (i) {
case 1:
syso(“低档”);
break;
case 2:
syso(“中档”);
break;
case 3:
syso(“高档”);
break;
default:
break;
}
}
应该就是这样吧
java高手进
父类:
public class Device {
private String dName;
private String address;
private double price;
public String getAddress() {
return address;
}
public Device() {
}
public Device(String dName, String address, double price) {
this.dName = dName;
this.address = address;
this.price = price;
}
public Device(String dName, String address) {
this.dName = dName;
this.address = address;
}
public String toString()
{
return "空调名称:"+this.getDName() + "\t出厂厂家:"+this.getAddress() +"\t价格:"+ this.getPrice();
}
public void setAddress(String address) {
this.address = address;
}
public String getDName() {
return dName;
}
public void setDName(String name) {
dName = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
子类:
public class AirCondition extends Device {
private int temperature;
public int getTemperature() {
return temperature;
}
public void setTemperature(int temperature) {
this.temperature = temperature;
}
public AirCondition() {
}
public AirCondition(String dName, String address, double price,
int temperature) {
this.setDName(dName);
this.setAddress(address);
this.setPrice(price);
this.temperature = temperature;
}
public void raiseTemp(int temp) {
System.out.println("给空调升温" + temp + "度,现在的温度为" + temp
+ this.getTemperature());
}
public void lowerTemp(int temp) {
System.out.println("给空调升温" + temp + "度,现在的温度为"
+ (this.getTemperature() - temp));
}
public String toString() {
return "空调名称:"+this.getDName() + "\t出厂厂家:"+this.getAddress() +"\t价格:"+ this.getPrice() +"\t现温度:"+ this.getTemperature();
}
}
测试类:
public class Text {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
AirCondition air=new AirCondition("格力空调","格力",3000,45);
System.out.println(air);;
}
}
java--设计一个类空调类
public
class
airCondition
{
private
String
品牌;
private
String
颜色;
private
float
功率;
private
boolean
开关;
private
int
温度;
public
airCondition(String
品牌,String
颜色,float
功率,int
温度){
this.品牌=品牌;
this.颜色=颜色;
this.功率=功率;
this.温度=温度;
}
public
void
开启(){开关=true;}
public
void
关闭(){开关=false;}
public
void
升温(){温度++;}
public
void
降温(){温度--;}
public
boolean
开关状态(){return
开关;}
public
int
温度(){return
温度;}
public
String
颜色(){return
颜色;}
public
float
功率(){return
功率;}
public
String
品牌(){return
品牌;}
public
String
当前状态(){
return
"机器描述:
品牌:"+品牌()+"
颜色:"+颜色()+"
功率:"+功率()+"匹
"
+
"\n机器状态:
开关:已"+(开关状态()?"开":"关")+"
设定温度:"+温度()+"°";
}
public
static
void
main(String[]
args)
{
airCondition
空调
=
new
airCondition("格力","白色",2,25);
空调.开启();
while(空调.温度()20)
空调.降温();
System.out.println(空调.当前状态());
}
}
--------空调类.java--------
public
class
空调类
{
private
String
品牌;
private
String
颜色;
private
float
功率;
private
boolean
开关;
private
int
温度;
public
空调类(String
品牌,String
颜色,float
功率,int
温度){
this.品牌=品牌;
this.颜色=颜色;
this.功率=功率;
this.温度=温度;
}
public
void
开启(){开关=true;}
public
void
关闭(){开关=false;}
public
void
升温(){温度++;}
public
void
降温(){温度--;}
public
boolean
开关状态(){return
开关;}
public
int
温度(){return
温度;}
public
String
颜色(){return
颜色;}
public
float
功率(){return
功率;}
public
String
品牌(){return
品牌;}
public
String
当前状态(){
return
"机器描述:
品牌:"+品牌()+"
颜色:"+颜色()+"
功率:"+功率()+"匹
"
+
"\n机器状态:
开关:已"+(开关状态()?"开":"关")+"
设定温度:"+温度()+"°";
}
public
static
void
main(String[]
args)
{
空调类
空调
=
new
空调类("格力","白色",2,25);
空调.开启();
while(空调.温度()20)
空调.降温();
System.out.println(空调.当前状态());
}
}
.
用java写简易的空调遥控器,麻烦给帮忙实现个功能
这不简单,在while循环前再加一个while死循环,里面判断用户的输入,如果用户输入1,则break跳出循环,然后才执行下面的循环。
用java 设计一个空调遥控器
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("请按提示输入。");
}
}
}
}
关于java空调和空调提供jdk安装是什么意思的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。