Air Conditioner Applet


In this lab, you will be designing a Java applet that simulates an air conditioner. The applet will have an interface that allows the user to specify the outside temperature, the inside temperature, and the desired temperature. The air conditioner has four different modes for heating and cooling (stop, low, medium, and high). You will be writing a controller that changes the air conditioner mode during simulation to make the inside temperature match the desired temperature. You will be provided with code that modifies the temperature. An example of the applet is shown above. If for some reason it doesn't work on your browser, download the classes and run them on appletviewer (AirConditioner is the main class): Interface.class, Controller.class, TemperatureUpdater.class, AirConditioner.class, AirConditioner$TimeUpdater.class

This lab consists of four parts, which have been split into their own Java classes. The provided files have comments describing each method and variable. Further details will be provided in lab. Each class is decribed below:

Interface

The interface must allow the user to specify the outside temperature, the inside temperature, and the desired temperature. You must have two buttons that allow the simulation to be started and stopped. You must also have labels that specify the current heating and cooling mode of the air conditioner. The interface should also adjust the inside temperature during simulation. Download the skeleton code here.

Controller

The controller for your air conditioner attempts to set the mode of the air conditioner in order to make the inside temperature match the desired temperature. There are four modes available for you to use, which are implemented in the code as Controller.STOP, Controller.LOW, Controller.MED, Controller.HIGH. It is up to you to decide when to use each mode. The method you should use for updating the mode during simulation is update(). This method takes two parameters that specify the current inside temperature and the desired temperature. Download the skeleton code here.

TemperatureUpdater

The temperature updater modifies the inside temperature during the simulation based on the inside temperature, the outside temperature, and the current heating and cooling mode of the air conditioner. In order to avoid hardcoding temperature changes to work with your controller, you will be using a precompiled version of this class. To use this class, you will need to understand the following methods:
/**
 *  METHOD: setInitialTemperature
 *  DESCRIPTION: This method sets the initial temperature to be used.
 *  PARAMETERS: double inside - the initial inside temperature
 *              double outside - the initial outside temperature
 *  RETURNS: nothing
 */
void setInitialTemperature(double inside, double outside)

/**
 *  METHOD: update
 *  DESCRIPTION: This method updates the inside temperature based on
 *               the time that has passed since the last update,
 *               the heating mode, and the cooling mode.
 *  PARAMETERS: int milliseconds - specifies the time that has passed
 *                                 since the last update
 *              int heatMode     - specifies the heating mode that has
 *                                 been applied since the last update
 *              int coolMode     - specifies the cooling mode that has
 *                                 been applied since the last update
 *  RETURNS: nothing
 */
public void update(int milliseconds, int heatMode, int coolMode)

 /**
  *  METHOD: getInsideTemperature
  *  DESCRIPTION: This method returns the current inside temperature
  *  PARAMETERS: none
  *  RETURNS: double, specifying the current inside temperature
  */
public double getInsideTemperature()
setInitialTemperature() should be used at the start of a simulation to set the original inside and outside temperature. update() should be called on every timer event to determine the new inside temperature. getInsideTemperature() should be used to determine the new inside temperature after a call to update(). Download the class file here.

Air Conditioner

The air conditioner is the main class for the applet. It is responsible for creating the interface, conroller, and temperature updater. When the user starts the simulation, this class should start a timer that causes periodic updates to the air conditioner. When the simulation starts, this class should get all the temperatures from the interface and then initialize the controller and temperature updater. On each timer event, the controller and temperature should be updated and the interface should be notified to show the changes. Download the skeleton code here.