CMPS 144L Spring 2019
Lab #1: Temperature and IncDate Classes

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" 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 James Rumplestiltskin, your login ID would (probably) be james.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 "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 several methods need to be provided. Each such method is indicated 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): 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 user/program dialog with that application is shown to the right, with input entered by the user 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 specifying that either the temperature is to change by a specified number of degrees or be set to a specified number of degrees. Each command begins with either C (for changeBy) or S (for setTo), is 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 printed.

When you are confident that you have completed the class so that each of its methods fulfills its specification, use the File Submission System to submit the source code file into the "Lab 1" folder. Your lab instructor will show 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. Also, there are several private methods. At least one of them should be useful to you.


Activity #3: Complete the IncDate Class

In Chapter 1 of the Dale/Joyce/Weems textbook, the Java class Date is examined. Instances of this class are immutable (i.e., their states cannot be changed) because the class includes no transformer/mutator methods by which to do so.

The authors then introduce IncDate as a child class (or subclass, if you prefer) of Date. The name is shorthand for "incrementable date", reflecting the fact that IncDate includes a transformer/mutator method, increment(), the purpose of which is to change the state of a date by moving it one day "forward" in time.

However, the authors do not provide a body for the increment() method. Your job is to do that. To make that task easier, the version of IncDate that your CMPS 144 instructor has made available to you includes more than what the textbook authors provided. Specifically, it includes an isLeapYear() method and the declaration and initialization of an array that holds the number of days in each month of the year.

There is no need for you to pay much attention to the Date class, except to notice that its three instance variables (year, month, and day) will need to be referred to in IncDate's increment() method.

For the purpose of testing your work, the Java application IncDateTester is available. It should be self-explanatory.

When you've completed the IncDate class, use the File Submission System to submit it into the "Lab 1" folder.


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.