Lab 1: Getting Started
CS 141: Introduction to Programming and Ascii Art, Fall 2015


This lab will not be collected,

Netbeans on Your Laptop

Optional: If you have your own laptop, now is also a good time to get everything working on it. You can download Netbeans (see instructions on Links page). If you have problems, bring your computer to class to get help from the instructor or lab assistant. You can also stop by WITS to get help.

Video Help Resource

Netbeans Programming

Instructions for writing your first program:

  1. H Drive Folders: Before opening Netbeans, create a folder on your H drive called CS141. You should save all of the work you do in this course into this folder. Inside CS141, make 2 subfolders, one called Practice and another called Lab1. In class we will be writing a lot of practice programs. It is good to keep these separate from the labs you turn in.
  2. Open Netbeans: Double click on Netbeans to open it (if you can't find it, ask!) The icon looks like:
  3. Make a New Project:
  4. Creating a New Class: Right click on the project name in the Projects tab (left side of window). Select New→Java Class. For the Class Name, enter MyFirstClass and then click the Finish button. A new panel should open. Its tab name should be MyFirstClass.java.

  5. Entering the Code: The new panel (i.e. file) should contain several comments (these are gray in color) and the code:
    
    public class MyFirstClass {
       
    }
    

    Add code so that the final program looks like (pay careful attention to the indentation):

    
    public class MyFirstClass {
        public static void main(String[] args) {
            System.out.println("Hello Willamette!");
        }
    }
    
    Save your code but clicking the save button
  6. Running Your Program: Click the Run Project button .

    Congratulations, you have just written and run your first program!

  7. What Just Happened?: Now, exit Netbeans and navigate to your CS141\Lab1 folder. Look at what folders and files are stored there.

ASCII Art

In the very old days (before you were born!) computers could only display text. Each character on the keyboard was given a 7-bit code representation called it's ASCII code. This was later extended to 8 bits (the Extended ASCII code) so more symbols could be represented. For example, the ASCII code for the letter 'A' is 01000001. If we interpret this as a base 2 number (don't worry if you aren't familiar with base 2), it can be interpreted as the decimal number 65.

The ASCII code is still used as the underlying representation of what we call "text", or in the language of Java, "Strings". If you create a document in Notepad, your document is stored exclusively in ASCII. In the above program, we have the print statement:

System.out.println("Hello Willamette!");

The characters inside the quotes (Hello Willamette!) is a sequence of ASCII characters called a String.

"ASCII Art" are images that are created using only ASCII characters, for example:

Lots of examples can be found online, eg. see http://www.chris.com/ascii. You can write a Java program to generate your own ASCII art by using multiple System.out.println statements. Modify your program above so that it outputs a picture, e.g. a building, animal, etc. Warning - if you want to use a single backslash ("\"), you need to use two backslashes ("\\") because single backslash in quotes has a special meaning. We will learn more about this in Chapter 2.

We will look at all of the class's artwork in class!

Deliverables

This lab will not be collected. However, you are expected to understand and do everything in this lab. If you have questions, please ask either the instructor or lab assistant for help. Every lab builds on the previous labs. Thus, for the next lab, it will be assumed that you understand all of this.