$25
By the end of this activity you should be able to do the following:
Ø Create a program then compile and run it
Ø Add Javadoc comments to your program
Ø Generate documentation for your program
Ø Correct your source code structure using Checkstyle
Ø Submit your completed program to Web-CAT for grading
Directions
Part A: Using jGRASP and Checkstyle
• Set up file folder – Open a file browser on your computer (e.g., File Browser on Windows or Finder on MacOS), and set up an appropriately named file folder for this activity (e.g., Activity_01).
• Open jGRASP – e.g, On Windows, click the Start button in the lower left corner of the screen, then in the Search window, enter jgrasp then when jGRASP selected. On MacOS, enter Cmd-space, enter jgrasp, then double-click on it.
• Using the top menu in jGRASP, open a new Java window (File New Java). Enter the following Java statements to create a class called StudentInfo:
public class StudentInfo
{
}
• Click the Save button on the top menu, then in the Save As dialog, use the buttons to the far right of “Look In” near the top of the dialog to navigate up to the folder where you
want to save your program. If you have not yet created a course folder (and within it a folder for this activity) you can do that now by clicking the folder button to create a new folder. Click once on the name “New folder” to select it then click on it again and change the name to number of this course. Double-click the folder to open it, then (as above) create a folder for this activity and open it. If your program code is correct, you should see StudentInfo.java as the file name. If this is not the case, enter the file name manually. Now click the Save button at the bottom of the dialog.
• Click the Compile button , and fix any compile-time errors.
• Generate your CSD by either pressing F2 or by clicking the Generate CSD button on the toolbar at the top of the jGRASP desktop. Now turn on Auto Generate CSD (View then check the Auto Generate CSD box), so that the CSD will be generated each time you Load or Compile a file. You may turn this off/on at any time.
• Add a main method to the class. Be sure to replace the blank in the code below with the method name (don’t forget to re-generate the CSD):
2
•
• Now add the Javadoc comments for the class and the main method of this program by adapting the Javadoc comments on page 1 so that they describe this program and have your name, course info, and today’s date.
• Inside the main method, write three or more print statements: (1) the first prints Name: followed by your name (first and last) on the first line, (2) the second that prints Previous Computer Courses: on the second line, (3) the third prints three spaces followed by the name of a computer course you have had (or None if this is your first course), (4) if you have had more than one computer course, print an additional line for each course (be sure to begin each course line with three spaces). Don’t forget to put double quotes around the String literals in the println statements.
• Click the Run Checkstyle button on the jGRASP toolbar and correct any issues identified by Checkstyle. If you don’t see the Checkstyle button then Checkstyle has likely not been installed on your machine. On your personal computer, you will need to download and install (unzip) Checkstyle. You may also need to configure Checkstyle in jGRASP (Tools Checkstyle Configure) so that jGRASP can find the folder containing the Checkstyle JAR file.
• Toggle line numbers on/off by clicking on the toolbar. Most users leave line numbers on.
• Click the Browse button on the toolbar. This opens the jGRASP Browse tab on the folder that contains the file in the CSD window. You should see StudentInfo.java underlined in the Browse tab. You should also see the corresponding .class file (StudentInfo.class) that was generated by the compiler if your file compiled successfully. This file contains the bytecode for your program that is used to run your program when you click the Run button .
In Part B you will develop a second program CourseInfo.java and then submit both StudentInfo.java and CourseInfo.java at the same time to Web-CAT.
3
Part B: Using Checkstyle, Web-CAT, and jGRASP Projects
1. Using Checkstyle to Find and Correct Style Errors
• Download the Part B zip file and save it in your folder for this activity. Then extract the CourseInfo.java file (Windows: right-click on the zip file then select Extract All …; Mac OS X: just open the zip file).
• Open CourseInfo.java by double-clicking on the file in the Browse tab. You will be responsible for correcting style errors and logic errors that are present in the program. The first step is to modify the program to adhere to the course coding standard. To do this, run Checkstyle and correct all of the formatting issues that appear.
o HINT: Checkstyle states that the main method is missing a Javadoc comment, and this is true. Hint: Make sure that you know the difference between a // to end of line comment, a /* single or multiple line comment */, and a /** Javadoc comment */.
o HINT: For dealing with a source line over 80 characters, see page 1 of this activity.
• The program's expected output is shown below (the line numbers on the left are not part of the expected output):
1 2
3 4
5
This course provides an introduction to Java and object-oriented programming.
The course also introduces the basics of software development.
The original author of the program claims the program is correct because it "gets the point across," but you know that it is incorrect because the actual output of the program does not match the expected output above when you run it during testing. Correct the output errors by modifying the program.