This commit is contained in:
ldy
2026-03-01 23:18:55 -05:00
commit 67f753a5d1
3087 changed files with 218259 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Question1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@@ -0,0 +1,97 @@
public class AirConditioner {
//Instance Variables
private boolean powerOn;
private int mode;
private int temperature;
//Constructor-turn all settings to default
public AirConditioner() {
this.powerOn = false;
this.mode = 0;
this.temperature = 16;
}
//Methods
public void turnOn() {powerOn = true;}
public void turnOff() {powerOn = false;}
public boolean getPower() {return this.powerOn;}
public void setMode(int mode) {
//if power down
if(powerOn == false) {
System.out.println("Please turn on the AC first");
return;
}
//if invalid mode
if(mode < 0 || mode > 2) {
System.out.println("Invalid mode");
return;
}
//default
this.mode = mode;
}
public int getMode() {return this.mode;}
public void setTemperature(int temp) {
//if power down
if(powerOn == false) {
System.out.println("Please turn on the AC first");
return;
}
//if dry mode
if(mode == 2) {
System.out.println("Cannot set the temperature in the dry mode");
return;
}
//if invalid mode
if(temp < 16 || temp > 30) {
System.out.println("Invalid temperature");
return;
}
//default
this.temperature = temp;
}
public int getTemperature() {return this.temperature;}
//Test
public static void testAirConditioner() {
AirConditioner ac = new AirConditioner();
// test the constructor
System.out.println(ac.getPower() == false);
System.out.println(ac.getMode() == 0);
System.out.println(ac.getTemperature() == 16);
// test the power functions
ac.turnOn();
System.out.println(ac.getPower() == true);
ac.turnOff();
System.out.println(ac.getPower() == false);
// test the mode functions
ac.setMode(1);
System.out.println(ac.getMode() == 0);
ac.turnOn();
ac.setMode(5);
System.out.println(ac.getMode() == 0);
ac.setMode(2);
System.out.println(ac.getMode() == 2);
// test the temperature functions
ac.turnOff();
ac.setTemperature(20);
System.out.println(ac.getTemperature() == 16);
ac.turnOn();
ac.setTemperature(20);
System.out.println(ac.getTemperature() == 16);
ac.setMode(1);
ac.setTemperature(31);
System.out.println(ac.getTemperature() == 16);
ac.setTemperature(20);
System.out.println(ac.getTemperature() == 20);
}
}

View File

@@ -0,0 +1,8 @@
public class Start {
public static void main(String[] args) {
AirConditioner.testAirConditioner();
}
}