Skip to body

CWU Faculty Websites

Ed Lulofs homepage

Link | Link | Link | Link

Ed Lulofs

Winter 2017 Courses

CS 110 l
CS 302 Data Structures 2

CS 362
 

Ed Lulofs
Lecturer
Department of Computer Science
Central Washington University

LulofsE@cwu.edu
Ed Lulofs, Department of Computer Science, CWU
400 E. University Way, Ellensburg, WA 98926-7520

 

CS 110, Programming Fundamentals I, 5 Jan 2017
Lab 1: Your CS account, and jGRASP
Due 5 Jan, 5pm, Saved to Canvas.

   Computer Science

This lab is worth 100 points, and has four parts. The goals for this lab are:

• Gain access to your lab account that has been created specifically for your use in CS110.
• Create folders in your computer science account for the CS110 class, where you'll be placing your completed coding homework assignments and labs throughout the quarter.
• Use jGRASP to write, compile, and run your first java program.
• Upload your work to Canvas.

If you do not complete the lab in the time allotted, then please return to the lab in your spare time, and complete the lab by 5 Jan, 5 pm. For this lab, the printout of the lab is being provided for you. In subsequent labs, you'll navigate to the course website, where the lab PDFs will be posted.

I. Access your computer science account for CS110

1. Use the account ID and password on the last page of this handout and write your name, provide you signature, and date the CS lab password/username sign-up sheet being circulated in lab.

2. Sit at any of the computers in the lab, and log in to your account using the username and password that you've been given. At the initial blue screen press Ctrl-Alt-Delete (all at the same time) (Figure 1a) which will bring up a login prompt: “Log on to this computer” (Figure 1b). There, provide your username and password, click the right-arrow, and follow the instructions to reset your password to something more personal. Please be sure to remember your new password; you'll be using it throughout this quarter.


Figure 1a: At this screen press Ctrl-Alt-Delete   (all at the same time)


Figure 1b: At “Log on to this computer” screen, provide your username and password that you've    received for use in CS110.

3. You are now logged in to your computer account for the CS110 class. Log in this way, from now on, when coming to lab, or when you need to work on a homework assignment. All programs needed for this course are available via your CS110 account.


II. Create directories for homework and lab assignments

Throughout the quarter, you'll learn how to write java code. For those assignments that have a coding part, you will submit your code by uploading it to Canvas. Here are the instructions on how to make the necessary folders.

1. While logged into your CS110 account on a lab computer, mouse click on the Window Icon on the lower-left corner of your screen, and select “Computer” from the options on the right (Figure 7), and from the menu that appears, double click on the network U (which stands for  University) drive (your name) under Network Location.

Figure 7a: Select “computer” from the options displayed on the right


Figure 7b: Double click on your U drive in the “Network Location” part of the screen

2. You can use your U drive for your lab work. All submissions are to Canvas. You can create a folder in it which is called lab1. To create a folder, right-click with the mouse anywhere in the window that shows your U drive,  and select “New” from the menu, followed by “folder” (Figure 8a).

Figure 8a: Creating a new folder


III. Becoming familiar with jGRASP – your first Hello World Java program

Now that you have completed the perfunctory “paper work,” it's time to write some code. jGRASP is a lightweight Integrated Development Environment (IDE). You will be using it throughout this course to write, compile, debug, and execute your Java programs, as was discussed in lecture.

1. To start jGRASP, mouse-click on the windows icon in the lower-left hand corner of the desktop. If the jGRASP icon does not appear in the list of programs, type “jgrasp” into the search box. When found, click on the jGRASP icon, which looks like the following: 
 
jGRASP has several panels (Figure 9) and icon buttons. You'll explore some of these today. In this (and subsequent) labs, if you are asked to “write” java code, mouse-click inside the editor panel, and type java code into that panel.

Figure 9: jGRASP's editor panel is where you input java code. The file panel displays .java (and .class) files that you have created. The compile messages panel is where jGRASP displays compilation messages when you compile your code. The run I/O panel (not shown) shows the output that is generated by your program.

2. To create a new java file, mouse-click on the file menu, then select new, and finally click on Java
(Figure 10). Note there may be several other options other than Java on your computer.

 

 


Figure 10: To create a new java file, select the New option from the File menu, followed by the Java option.

3. Using the keyboard, type the text that is shown in Figure 11, into the editor panel of the new java file that you just opened.  Type the code EXACTLY as shown. Be careful to include semicolons and brackets, and to use proper capitalization.  Change the comments accordingly, by adding your name to the right of “Author” and the date. Remember that adding blank lines makes your code easier to read.

On all submissions, you will always be graded off for not including the three comment lines: name, date, file/description.

Figure 11: Text for the HelloWorld java program.

4. Once you've entered the text in Figure 11 into the editor panel of jGRASP, save your code into a file that is called HelloWorld.java. Recall from lecture that the name of the .java file must end in .java. To save a file, click on the save button (Figure 12a). A menu/dialogue box will appear, and will ask you where you want to save your file.
Upload your HelloWorld.java file to Canvas lab1.
Ignore the “.class” file. I will try to have the Canvas upload link in two locations: The week it is done and the Labs module. When you have successful saved your file in the right location, it should appear in the file panel as HelloWorld.java.

Figure 12a.   The save button


Figure 12b   The compile button


Figure 12c   The run button


Figure 12d   The line-numbering button

5. Recall from lecture and from the textbook readings, that the java compiler converts your human- readable text in a .java file into a .class file (the computer byte code) that is invoked using the Java Virtual Machine (JVM). To compile your java code, click on the compile button (Figure 12b).

6. If you have typed into the editor panel the code from Figure 11 exactly, with no errors, then the compile messages panel will display no errors (Figure 13). If you have typed java code that has a syntax error, an error message will be displayed in the compile messages panel. If that's the case, you'll need to find the syntax error in your .java code, and compile again. Ask a TA or the lab instructor if you have questions.


Figure 13: jGRASP's compile message panel displays status and error messages that arise when you compile your program. When the code is error- free, the compile message is empty.

7. If your HelloWorld.java code compiles correctly, you'll see a “HelloWorld.class” file in the file panel. Once you've done that, it is time to invoke the Java Virtual Machine. In other words, you want to run the program. To do that, click on the run icon (Figure 12c). The output of your program will appear in the Run I/O tab (Figure 14).

Figure 14: The output of your first java program, which prints “Hello World!” to the screen.

Click the pointer in the output window. Select all. Copy and paste it to a text file, usually called “output.docx”.

8. That's it. You now know how to write, compile, and execute a java program using jGRASP. One additional feature that you can enable is line numbering. Click on the line-numbering button (Figure 12d), and jGRASP will automatically line-number you code. Line numbering is useful, especially if you are talking to somebody about your code; it allows you to refer to different line numbers so that the person you are talking to knows which part of the code you are discussing. Be sure to save your HelloWorld.java file if you make any changes to it, so that it can be graded.


IV. What to Hand In, Grading, etc.

For this first lab, your code can be saved to your CS110 account, and must be uploaded to Canvas. Here's what we are looking for, when grading your submission. In later homework assignments and lab submissions, there will be additional items that will be graded, which will be described in future lectures.

1. Each .java file must be thoroughly commented. If your code does not compile because you've been unable to fix a syntax error, then the comments will allow you to receive partial credit.
2. Your java code must be indented, so that the code is easy to read (more on this in future lectures). For this lab, make sure that the following two files are in your lab1 folder and uploaded to Canvas:

HelloWorld.java
output.docx

There will be additional files (the .class files, for example) in your lab1 folder, but don't worry about them. Those files are not graded; they are just the byte code files that are used by the Java Virtual Machine.
Finished, graded by a TA, and submitted before the end of lab is 20% extra credit.
 

Take the Next Step to Becoming a Wildcat.

Admissions@cwu.edu