、创建一个空调类,属性有品牌(美的、格力、奥克斯)、价格、类型(立式空调、挂机空调、中央空调),空调有制冷、制热、定时制冷、定时制热的方法,创建出该方法。要求至少创建两个构造方法,然后通过测试类进行测试。
时间: 2023-10-20 19:08:05 浏览: 179
好的,这个问题是关于编程的技术问题,我可以回答。下面是实现代码:
```
public class AirConditioner {
private String brand;
private double price;
private String type;
public AirConditioner() {}
public AirConditioner(String brand, double price, String type) {
this.brand = brand;
this.price = price;
this.type = type;
}
public void cool() {
System.out.println("空调正在制冷");
}
public void heat() {
System.out.println("空调正在制热");
}
public void timedCool(int time) {
System.out.println("空调将在" + time + "分钟后开始定时制冷");
}
public void timedHeat(int time) {
System.out.println("空调将在" + time + "分钟后开始定时制热");
}
public static void main(String[] args) {
AirConditioner ac1 = new AirConditioner("美的", 1000, "挂机空调");
AirConditioner ac2 = new AirConditioner("格力", 2000, "中央空调");
ac1.cool();
ac2.timedHeat(30);
}
}
```
测试类:
```
public class AirConditionerTest {
public static void main(String[] args) {
AirConditioner ac1 = new AirConditioner("美的", 1000, "挂机空调");
AirConditioner ac2 = new AirConditioner("格力", 2000, "中央空调");
System.out.println("空调1品牌:" + ac1.getBrand());
System.out.println("空调1价格:" + ac1.getPrice());
System.out.println("空调1类型:" + ac1.getType());
System.out.println("空调2品牌:" + ac2.getBrand());
System.out.println("空调2价格:" + ac2.getPrice());
System.out.println("空调2类型:" + ac2.getType());
ac1.heat();
ac2.timedCool(60);
}
}
```
阅读全文