CPE 102 Lab 1


This lab is to be completed individually. You are permitted to seek assistance from a peer if you get stuck.

Prerequisites:
You must have a working account on the CSL workstations.
You must be able to login to CentOS and navigate the menu system to launch a text editor (gedit).
You should have basic familiarity with using the Terminal program and issuing simple Unix commands such as ls and more.

Part 1

Login to CentOS with your Cal Poly username and complete this short tutorial: Compiling & Running a Simple Java Program from the command line. (You can skip the section about installing Java; the Java compiler is already installed on the lab computers.)

Download the source code for NumberDemo.java to your account.
Compile and run NumberDemo.java at the command line.
Run it with several times with different inputs.
What happens if you enter a letter instead of a number?


Part 2

Make a launcher for BlueJ.

Compile and run NumberDemo.java using BlueJ:
  1. From the "Project" menu select "New Project". (You may name it "Lab1".)
  2. Click the "New Class" button to create a new Java class named NumberDemo.
  3. Right-click on the newly created NumberDemo class in the diagram and select "Open Editor". Observe that BlueJ creates the skeleton code for a class. You may select all (Ctrl-A) and delete the skeleton code.
  4. Copy and paste the source code for NumberDemo.java into the editor window.
  5. From the "Options" menu, select "Preferences" and in the preferences dialog, check "Display line numbers". Click OK, and observe the line numbers displayed in the left margin.
  6. Click the "Compile" button. In the status window you should see the message "Class compiled - no syntax errors."
  7. In BlueJ's main window, right click on the NumberDemo class in the diagram and select "void main(String[])". In the dialog which appears, click "OK".
  8. BlueJ's terminal should appear in which you can interact with the program.
  9. Exit BlueJ.


Open a terminal window and navigate to the project folder you created for your BlueJ project in the previous step.
Use a text editor such as nano, vi, or gedit, to modify the program so it checks if the number is negative and if so, prints an appropriate message.
Compile and run the program at the command line.
Repair any errors until the program runs correctly.

Part 3

Correct coding standard violations:
  1. Download the Checkstyle extension for BlueJ that contains the custom checks for our class coding standard. The extension is installed by placing the extension jar file into an extensions directory. /home/yourusername/.bluej/extensions
    (In the file manager, View -> Show hidden files will reveal "dot" folders. You should create the extensions directory if it doesn't exist. )
    Restart BlueJ.
  2. From the Tools menu, select Preferences. The preferences dialog appears. Click on the Extensions tab. Locate the Checkstyle panel. For Configuration File enter the location of the class configuration XML file: /home/graderjd/bin/bluej/lib/extensions/102styleBlueJ.xml
  3. Launch BlueJ and open the previous project.
  4. From the main window (not the editor) open the Tools menu and select Checkstyle. In the window that appears, click on "NumberDemo" in the left-hand panel. A list of checkstyle violations appears along with the corresponding line number.
  5. Your assignment is to learn about the class coding standard by correcting the errors that Checkstyle has identified. Leave both the Checkstyle window and the editor window open. When you make a a change in the editor and click "Compile" the Checkstyle window will automatically refresh itself. The following strategy is suggested:
    1. Look for errors whose message is immediately obvious. For example, "'{' should be on a new line" needs no further explanation.
    2. Consult the coding standard checklist or coding standard definition if you aren't sure how to fix the error or what the correct standard requires.
    3. Read an explanation for a few of the most common errors.
    4. If the error message doesn't make sense to you, consult the Checkstyle documentation for an explanation of the error message.
    5. As a last resort, consult the instructor.
Summary
Since maintenance accounts for 80% of most organizations software budget, writing readable code can produce significant cost savings for a software team.  You may find that correcting Checkstyle violations is somewhat tedious.  To avoid this, familiarize yourself with the class coding standard and write your code in the correct style at the outset.  That will save a lot of time because you won't have to go back and correct it when you are finished.

Submission

At the top of the source code, change "@author J. Dalbey" to your name, and change the version to 1.1.
Submit the source code file to PolyLearn for Lab 1.



For Home Use:

Here are directions for installing BlueJ and Checkstyle on your personal computer.

Also, on Unix, Checkstyle is installed in the grader account.  To run the command line version:
~graderjd/bin/stylechecker myprogram.java