Fundamental Programming Concepts
Summer 2000

Lab 1

Overview
This lab will involve several Internet tasks and a small Java program. The goal is to introduce you to the Internet resources available in this class and help you to become accustomed to using these resources. You will: 
  1. Find information on a web page
  2. Write a program
  3. Send email
  4. Post to a newsgroup
  5. FTP your program to turn it in electronically
Hopefully you are already familiar with some of the above tasks. If not, you will be soon!

Note that if you're reading this handout on a printed page, rather than online, you'll frequently see underlined words. These are hyperlinks that, when viewed online, can take you to pages with more information.

 

Part I: The Course Webpage

The programs we'll be using in lab to access the Internet are supplied through Bear Access, a suite of programs that Cornell makes available. In Upson B7, you can start Bear Access by using the Start menu: Start->Programs->Bear Access->Bear Access via Runway. Bear Access supplies Netscape Communicator for a web browser, Eudora for email, and WinVN as a news reader.

  1. Use a web browser to go to the course website. The course website can be found at http://www.cs.cornell.edu/courses/cs99/2000su. Find the handout page for this lab. Follow this link to find the secret phrase. Make note of it -- you'll need it in Part II.

 

Part II: Java
For this course we will be using a compiler called CodeWarrior that is made by Metrowerks. It is an IDE, which stands for Integrated Development Environment. This means that the editor, compiler, and debugger are all part of one big program. 

Creating the Project

You will need to create a CodeWarrior project for each program you write. A project can contain several source files, libraries, and other items. To create a project for this lab, follow these instructions.

Don't forget that when you're done working for the day, you'll need to copy your project to a disk, and then logout of the machine you are working on (Start->Logout).


Your First Program

Now that we have the project created, let's write some code! Enter the following code in the Lab1.java file:

/**
 * CS99 Lab 1
 * Author: your name here
 * NetID: your NetID here
 * Date: today's date
 */
class Lab1 {
    public static void main(String[] args) {

        System.out.println("Hello, world!");
    }
}

Absolutely everything is important -- the spelling, capitalization, punctuation, etc. Now try to run your program. You can do this by doing any of the following:

  • Clicking the arrow on the Project window (4th icon to the right of "Java Application", turns green when you hover the mouse over it
  • Going to the Project menu and choosing Run
  • Pressing F5

If all goes well, you'll soon see a message on the screen saying "Hello, world!". Congratulations! You've written your first Java program. If not, you have your first bug to fix. The compiler will show you a list of errors. You can click on each error in the list, and it will take you to the statement in the program that the error is in. Try to figure out what you did wrong, correct it, and then try running the program again.

By the way, println is a method that prints a message to the screen. Its name stands for "print line". It is a method that belongs to the System.out object. We'll talk more about objects later. 


Your Second Method

main was your first method, in case you didn't realize it. Recall that a method, or function, is a sequence of statements that perform one well-defined task. Let's keep it simple at first - let's write a method called printHello, that just prints "Hello, world!" When we're done we'll have two methods in our Lab1 class - main and printHello.

 

How do you include multiple methods in the same class? Well, let's say we had a class named Cat, and methods named scratch and sleep. Then we would write something like this:
class Cat {

    static void scratch() {
        ...
    }
          
    static void sleep() {
        ...
    }

    ...

}

Remember: all methods go inside classes, and methods never go inside other methods.

Here's how to write our new method:

  1. First, you'll need to write the signature for the method. This is the first line of the method, and for now may contain some keywords that don't make a lot of sense. We'll eventually learn what they all mean in this course. Here's the signature for our new method, which we'll call printHello
        static void printHello()
  2. Now, write the body of printHello. Don't forget the braces around it. 
  3. Finally, we'll change main to call printHello. Calling a method means transferring control to it. To do this, change main to: 
        public static void main(String[] args) {
            printHello();
        }
Now run the program again. You should get exactly the same output as you did before. Once you have that working, try calling printHello several times in a row: 
public static void main(String[] args) {
    printHello();
    printHello();
    printHello();
}
You should get three messages in a row. Now, for fun, try changing println to just print, and run the program again. Notice what the difference is in the output. Change it back to println when you're done. 

 


The Real Program (for this lab)

Now it's time to write your own program -- the real one for this lab. This is the program you will submit. To prepare for it, keep your Lab1 program open. Get rid of all the statements inside main, but make sure to leave your printHello method in the program. 

Write a new method, called printInitials, that prints your initials to the screen. It should look something like this:

M   M  RRR    CCC
MM MM  R  R  C
M M M  RRR   C
M   M  R R   C
M   M  R  R   CCC
Your letters should be at least 5 rows tall.

Also, write another new method called printSecretPhrase. It should print to the screen the secret phrase that you found on the course website in Part I.

Now rewrite your main method to make calls to printHello and printInitials so that you get output like the following: 

 
Hello, world!

M   M  RRR    CCC
MM MM  R  R  C
M M M  RRR   C       <----- These should be your own initials, not MRC
M   M  R R   C
M   M  R  R   CCC

the secret phrase

Hello, world!

That's a hello, a blank line, your initials, a blank line, the secret phrase, a blank line, and another hello. The blank lines can be produced with the following call to println:

System.out.println();
This is the only kind of call to println that your main method is allowed to make. Note that you could also make another method to do this, if you wanted. 

The program will be graded on these criteria:

  • Style
    • Correct indentation
    • Consistent brace placement
    • Comment at beginning of class
  • Correct output, as above
  • Methods
    • Correct division of output
    • Correct signatures
 
Part III: Email and Newsgroup
For this part of the lab, you will need to have your Cornell NetID and password. If you don't have these yet, you'll need to go to the CIT helpdesk located at the CCC building, and bring a photo ID with you. 
  1. Send email to the course staff. The address is cs99@cs.cornell.edu. Use this subject: 
        "CS99: Lab 1 Roll Call" 
    (don't include the quotes). Include your name in the body of the message. If you've never sent email using your Cornell address, you'll want to make a Eudora floppy first. See the lab consultant in B7 if you don't know how to do this.
  2. Post to the course newsgroup. You can find news readers in Bear Access. The course newsgroup is cornell.class.cs099. You'll find a post in it with a subject of "Lab 1 Roll Call". Post a response to that message that includes your name. Since many people may not have posted to newsgroups, there is a separate set of instructions for this.
Don't neglect sending the email and posting before lab on Thursday! They will be part of your grade for this lab.

 

Part IV: Submit Your Lab
To submit your lab, follow the instructions on the separate handout about submitting labs. You will need your Cornell NetID and your Instruct password.

Important change: we will not be using FTP to turn in labs for the first week. You will turn them in on floppy disk, as described on the instruction page linked above. This is a result of extraordinary number of people in the class, 30 of whom do not yet have FTP accounts.

Files to submit:

  • Lab1.java
  • Lab1.mcp
Don't forget to submit your lab before lab on Thursday!