Homework 1

Temperature Application

Announcement (posted 1/24): I have modified the list of files that you must submit with this assignment. You can put all your code into a single file named Thermometer.java and then jar up that one file. If you already started the assignment and are using the MVC model, that is fine. However, since we will not discuss the MVC model until Tuesday, it is not necessary to use it in this assignment.

Create a temperature application that produces a drawing that looks like a mercury thermometer . The thermometer 's value should be based on a value input by the user. The user should also input a minimum and maximum value for the temperature. Two example screen shots appear below (the mercury should be in red, not blue--for some reason when I take screen snapshots the mercury ends up looking blue rather than red):


 



Specifications for the temperature application

  1. The application should be placed in a package named "temperature".
  2. The application should be invoked as a jar file:
  3.     java -jar temperature.jar minValue maxValue value
  4. The height of the thermometer's rectangle should be 3/4 the height of the window.
  5. The width of the thermometer's rectangle should be 1/15 the height of the rectangle
  6. The bulb should be 3 times the width of the thermometer.
  7. The labels for the minimum, maximum, and user-specified value should be in bold, 12 point Helvetica font
  8. The labels should be centered vertically with respect to the temperature that they display and should be offset 5 pixels from the sides of the thermometer (do not hard-code 5 wherever you need to use it--use a constant instead!).
  9. The thermometer should be centered horizontally in the window. To simplify the assignment, the thermometer's rectangle should be centered vertically within the window and the bulb should be tacked onto the bottom by centering the bulb at the bottom of the thermometer's rectangle. That is why the thermometer does not appear centered in the two windows.
  10. There should be a horizontal line showing where the bottommost temperature range of the thermometer begins (that would be the horizontal line next to the 0 in the above screen snapshots).
  11. The bottommost temperature should start at the following location:
  12.      bottom temperature location = thermometer rectangle's bottom - bulbWidth
  13. You will need to submit the following files:
    1. Thermometer.java: An implementation of the thermometer
    2. temperature.jar: A jar file that contains the class file for Thermometer.java plus a manifest.txt file that points to Thermometer as the class containing "main". The manifest.txt file will need to contain the fully qualified name of the Temperature class.


Hints

  1. Use the Slider Application presented on the sample code webpage class as a guide for your implementation. You do not have to separate your code into a model and graphical view as is done in the demo code. It's fine to bundle everything into one file. You will get practice with the Model View Controller model later in the course.
  2. drawRect can be used to draw the outline of a rectangle and fillRect and fillOval can be used to create filled rectangles and circles.
  3. In order to prevent the black outline of the thermometer's rectangle from enclosing the mercury, you will need to draw both a red-outlined rectangle and a filled red rectangle
  4. Text is drawn at the baseline so if center  represents the vertical center of the text, the text can be vertically centered by subtracting half of the text's height from center.