CMPS 144L Fall 2019
Lab #1: Preliminaries and the Temperature Class

Activity #1: Preliminaries

Before you get started on the "real" work of this lab, there are a few preliminary steps to take care of. If necessary, your lab instructor will help you through these.

Register for the Lab and Lecture parts of the course

To begin this first lab, you should click on the "Student File Submission System" link near the top of the CMPS 144L course web page, and then click on the "Register" link on the page that appears. That should take you to a page on which you provide your Royal Number (which is an upper case 'R' followed by eight digits) and then you specify (twice) a password to be used in order to make use —for the rest of this semester— of the file submission system for this lab course. You are required to use a "strong" password, meaning one that has length at least eight, includes a lower case letter, an upper case letter, a digit (0..9), and a character in none of those categories (e.g., $, #, &). It is important that you remember your password, as you will need to use it throughout the semester.

After you've registered, verify that you can log in. (Click on the "Log in" link and then, on the page that appears, enter your login ID and password in the two text boxes (login ID on the left, password on the right).) Note that your login ID is not your Royal Number but rather the prefix of your U of Scranton e-mail address up to but not including the @ symbol. Thus, for example, if your name were Sarah Rumplestiltskin, your login ID might be sarah.rumplestiltskin.

Having registered for CMPS 144L, do the same for CMPS 144, the lecture part of the course. To do that, first go to the CMPS 144 course web page, click on "Student File Submission System" and then on the "Register" link. As before, enter your Royal Number. At this point, you should get the message Prior registration bound to this context!, which means that you have successfully registered for both the lab and lecture parts of the course and your login ID and password are the same for both.

Install Java SE and jGrasp

In order to do Java programming on your computer, it must have Jave SE (Standard Edition) installed on it. If you don't already have that (e.g., from when you took CMPS 134), you should do install it now. Version 8 (or later) would be fine.

There are a variety of "integrated development environments" (IDEs) intended to provide support to a programmer (to make the task of programming as easy as possible). The one that we encourage students to use in the first couple of CMPS courses is jGrasp. If your computer doesn't already have it (e.g. from when you took CMPS 134), you are encouraged to install it. Use the link in the previous sentence to get to the jGrasp website.


Activity #2: Complete the Temperature Class

This lab activity is intended to reacquaint you with object-oriented programming in Java. Specifically, you are to download an incomplete version of the Temperature class and to complete it. The bodies of one constructor and five methods are missing, each one having been replaced by the comment STUB!!. Before trying to develop your own code for the stubbed methods, study the code that is already there, as it should give you a model to mimic.

Enter an initial temperature reading, which
should be a number optionally followed by C or F: -5C
Calling Temperature(-5.000000,true)

toString() yields      -5.0C
toString(true) yields  -5.0C
toString(false) yields 23.0F

Enter command (H for help): C +18F
Calling changeBy(18.000000,false)

toString() yields      5.0C
toString(true) yields  5.0C
toString(false) yields 41.0F

Enter command (H for help): S 45
Calling setTo(45.000000)

toString() yields      45.0C
toString(true) yields  45.0C
toString(false) yields 113.0F

Enter command (H for help): D 68F
Computing difference between 45.0C (113.0F) and 20.0C (68.0F)
  difference(20.0C, true) yields 25.000000
  difference(20.0C, false) yields 45.000000
  difference(20.0C) yields 25.000000

toString() yields      45.0C
toString(true) yields  45.0C
toString(false) yields 113.0F

Enter command (H for help): Q

Goodbye.
You are not to change the signature1 of any of the public methods, or to add any public methods.

To test your work, you are expected to make use of jGrasp's Workbench feature and/or the TemperatureTester application. An example of a user/program dialog with that application is shown to the right, with input entered by the user shown in boldface.

The application begins by inviting the user to enter an initial temperature value, which is specified by a numeral optionally followed by either C or F (to indicate Celsius or Fahrenheit, respectively). (The default is Celsius.)

Thereafter, the user is expected to enter commands, each of which indicates either that the temperature is to be

Each command begins with a one-letter code —C for Change, S for Set, or D for Difference— followed by a numeral and then, optionally, either C or F (to indicate Celsius or Fahrenheit, respectively). The Q command causes the program to terminate. The H command causes a few example commands to be displayed.

Not surprisingly, these commands are translated by the application into calls to methods in the Temperature class, namely changeBy(), setTo, and difference().

When you are confident that you have completed the class so that each of its methods fulfills its specification, use the Student File Submission System to submit the source code file into the "Lab #1" folder. (See the link to it near the top of the CMPS 144L course web page.) Your lab instructor will assist you, if necessary.

One of your goals should be to complete the class without introducing any assignments to the instance variable. That is, the only method that should include a statement of the form celsiusDeg = X (where X is some expression) is the version of setTo() that was provided to you.

Another goal should be to re-use code wherever possible, rather than repeating code. For example, if two methods have similar purposes but one of them is specific to a particular temperature scale (e.g., Celsius) and the other method handles either scale, one of those methods should call the other one. (For a good example of this, see how the argument-less version of toString() calls the one-argument version. A similar relationship holds between the two versions of setTo().)

A third goal is to make use of the provided private methods. Calls to private methods would be appropriate in the degreesFahrenheit() method and at least one of the changeBy() methods.


Footnote

[1] For the purposes of this lab, the signature of a method is given by its return type and the list of data types of its formal parameters.