Lab #1: Programming Exercise

Before starting NetBeans be sure that you have created a folder in which to store your CIT-260 project folders and associated files. Now, start NetBeans on your computer. Then on the menu bar, select File and New Project. you should see a dialogue box like this:

new project dialogue

If not already selected, select the Java category. Then under Projects select Java Application. Then click on the next button. You should see a window open up that looks like this:

enter file name

Type in the project name "Lab01". Then for the project location, browse to the folder you have prepared for your CIT-260 assignments. When you click the Finish button, you will be presented with a window that looks like this:

code window

The left pane shows the list of files that NetBeans has created for this project. Source code files are organized into Packages. The right pane is the code editor window. Here is where you will enter in the source code for your program. Notice that NetBeans has already created some code for you. For this lab, you will change some of this code.

Code Changes

First of all, you need to add a file prologue. The file prologue belongs at the top of the file and looks like this:

// File Prologue
// Name: <--- be sure to add your name here
// Project: lab01"
// Date: <---- add today's date

The Java code that NetBeans created for you should look something like this:

package lab01;
 
public class Lab01 {
   public static void main(String[] args) {
      // TODO code application logic here
   }
}

The first statement

   package lab01;

tells us that the source code in this file belongs to the package named lab01. NetBeans created this package for you. Related source code files are put into the same package.

The next statement

   public class Lab01 {

declares a class named Lab01. Every Java program must have at least one class and each class has a name. By convention, class names start with a capital letter. The keyword public in front of the class name tells us that the class can be seen from anywhere in the program. Following the class name is an opening curly brace "{". All of the code that belongs to a class is enclosed in a set of curly braces. The code enclosed within a set of curly braces is called a block.

The next line of code

   public static void main(String[] args) {

defines the main method of the program. A method is a collection of statements, and every program must have a method named main. This is called the entry point of the program, and it defines where execution of your program begins. Following the name main is a a pair of parentheses that enclose the parameters for the main method. At this point we are not concerned with the values in the parantheses. At the end of this line is another opening curly brace. All of the statements inside of the main method will be enclosed in a pair of curly braces.

Finally, inside of the curly braces for the main method is the line

   // TODO code application logic here.

The two slash marks tell us that this line is a comment. Comments are ignored by the compiler. Delete this line, and add the line of code

System.out.println("Woohoo ... I did it!!");

This line of code tells the program to output the text enclosed within the quotation marks to the console. In computer-speak, the console is the display screen on your computer. This line of code is a statement. Every statement in Java must end in a semi-colon, kind of like sentences end with a period.

Your program should now look something like the following. Notice that I have re-arranged the curly braces so that the opening and closing curly brace for a block of code line up in the same column. I prefer this format as it makes the code easier to read.

Now compile and run your program by clicking on the green triangle. You should see the output of your program on the bottom pane of the NetBeans window, like this:

Submitting your lab

To submit your lab place the entire project folder you set up for this assignment in a zip file and name the zip file lab01.zip. Submit the assignment as Lab #1 on I-Learn.

Grading Guidelines

Description Points possible

Assignment meets the following guidelines:
o Source code files contain a declaration that you did not copy any code, except that provided.
o Program has been properly submitted to I-Learn
o Code meets style guidelines

2

Program executes correctly, and meets the specification.

3
Total 5