// File $CISC370HOME/example-progs/threads/animation/Thermometer.java /** * File $CISC367HOME/example-progs/threads/animation/Thermometer.java * * Defines a thermometer object and extends Observable */ import java.util.*; // for class Observable public class Thermometer extends Observable { String title; // Instance variables int minTemp, maxTemp, temp; public Thermometer() // Default constructor { title = "Farhenheit Thermometer"; minTemp = 0; maxTemp = 100; temp = 50; } public Thermometer(int temp) // Constructor { this(); this.temp = temp; } public Thermometer(int minTemp, int maxTemp, int temp) // Constructor { this(temp); this.minTemp = minTemp; this.maxTemp = maxTemp; } public Thermometer(String title, int minTemp, int maxTemp, int temp) { this(minTemp,maxTemp,temp); this.title = title; } public void setTitle(String t) { title = t; changed(); // Notify observers of change } public String getTitle() {return title;} public void setTemp(int t) { if (0 <= t && t <= 100) temp = t; // Set temperature else { System.out.println("New temp out of range. Setting to default of 50F"); temp = 50; // Set to default if t out of range } changed(); // Notify observers of change } public int getTemp() {return temp;} public int getMinTemp() {return minTemp;} public int getMaxTemp() {return maxTemp;} private void changed() { setChanged(); // Signal that a noteworthy change has occurred. notifyObservers(); } }