I have a programming assignment where I'm basically supposed to have a Thermostat class and a main. With the Thermostat, you set the desired temperature and heating/cooling and once it gets to that temp it shuts off. It also contains a cooling and heating threshold so that if it gets to either one, the mode switches from heating to cooling or vice versa. It also contains some time-related info in which the degree should show the temperature changing by 1 every minute. The main is just used as a test to visually display the thermostat and to show the professor that it powers off, switches mode, etc. I think I have most of this, but I'm still having a few problems and can't figure it out. I will insert my code below in case anyone has any suggestions.
import java.util.*; public class Thermostat { public double currentTemperature; public double desiredTemperature; public boolean heating; public double heatingThreshold; public double coolingThreshold; public boolean power; Calendar cal = GregorianCalendar.getInstance(); public double getCurrentTemperature() { return currentTemperature; } public void setCurrentTemperature(double currentTemperature){ this.currentTemperature = currentTemperature; if (currentTemperature >= desiredTemperature && heating == true); power = false; if (currentTemperature <= desiredTemperature && heating == false); power = true; if (currentTemperature >= heatingThreshold); heating = false; if (currentTemperature <= coolingThreshold); heating = true; } public double getDesiredTemperature() { return desiredTemperature; } public void setDesiredTemperature(double desiredTemperature) { this.desiredTemperature = desiredTemperature; } public boolean isHeating() { return heating; } public void setHeating(boolean heating) { this.heating = heating; } public double getHeatingThreshold() { return heatingThreshold; } public void setHeatingThreshold(double heatingThreshold) { this.heatingThreshold = heatingThreshold; } public double getCoolingThreshold() { return coolingThreshold; } public void setCoolingThreshold(double coolingThreshold) { this.coolingThreshold = coolingThreshold; } public boolean isPower() { return power; } public void setPower(boolean power) { this.power = power; } public void advanceOneMinute(){ cal.add(Calendar.MINUTE, 1); if (heating = true); currentTemperature =+ 1; if (heating = false); currentTemperature =- 1; } public void advanceOneHour(){ cal.add(Calendar.HOUR, 1); if (heating = true); currentTemperature =+ 60; if (heating = false); currentTemperature =- 60; } public String currentStatus(){ String output = ""; if (power == true); output += "\tPower: On" + "\n"; if (power == false); output += "\tPower: Off" + "\n"; if (heating == true); output += "\tMode: Heating" + "\n"; if (heating == false); output += "\tMode: Cooling" + "\n"; output += "\tDesired Temperature: " + desiredTemperature + "\n"; output += "\n\tCurrent Temperature: " + currentTemperature + "\n"; return output; } }
import java.util.*; public class Assignment { public static void main(String[] args) { // TODO Auto-generated method stub Thermostat house = new Thermostat(); house.power = true; house.heating = true; house.currentTemperature = 65.0; house.desiredTemperature = 67.0; house.heatingThreshold = 70.0; house.coolingThreshold = 60.0; } System.out.println(house.currentStatus()); System.out.println("5 minutes later"); house.advanceOneMinute(); house.advanceOneMinute(); house.advanceOneMinute(); house.advanceOneMinute(); house.advanceOneMinute(); System.out.println(house.currentStatus()); System.out.println("Turning Thermostat Power Off..."); System.out.println(house.currentStatus()); System.out.println("2 minutes later..."); house.advanceMinute(); house.advanceMinute(); System.out.println(house.currentStatus()); System.out.println("One hour later..."); System.out.println(house.currentStatus()); }