CSCI 241 Labs: Lab 1

CSCI 241 Labs: Lab 1
Working in the Lab with BlueJ


Objectives

In this lab you will explore the Linux operating system and the BlueJ Programming Environment.

Work with your partner and read the handout carefully as you go along. Make sure you EACH try every exercise.

Getting your account

  1. Make sure that you have filled out, signed, and returned an account policy sheet.

  2. Our System Administrator will lead you through the steps to establish your account for this class. These steps are summarized in the prelab reading, as well.

There are 6 checkpoints in this lab. If you need help with any problem, raise your hand.

Getting Started

Your instructor and System Administrator will help you set up your account and account preferences. We repeat some information here from prelab1 for review.
  1. Log in to the computer by entering your name and password. If your login is successful, there will be a short delay followed by the display of some startup Gnome windows (Gnome is your Desktop Manager Program.) Close any windows that show up by clicking on the X in the upper right-hand corner of the window.

  2. Look for the Applications menu in the top left corner of the screen. Click it to see Favorites, then click Terminal. panel at the top of the screen with several icons on it. Click on the terminal icon. You should get a terminal window titled with your login name, machine and current directory location. The cursor should appear to the right of the prompt "[login-name@vegetable-name~]$".

  3. Log out by clicking on your name in the top right corner of the screen and selecting the option, "Log Out". Another dialog box will then appear from which you can confirm that you want to log out.

  4. At this point you would normally walk away from the machine, but today we want you and your partner to practice logging on and off. Do so now.

Getting Lab Materials

Before we start, it would be a good idea to try to be somewhat organized! There is nothing worse that completing an assignment or lab and not being able to find it. So, your instructors suggest creating a directory hierarchy that organizes your files. Let's start by creating some directories.

  1. Open a terminal window. When you first open your terminal window, you are placed in your home directory.
  2. Create a new folder for CSCI 241. To do this, execute the following command:
          mkdir Cs241 
  3. Make the new directory your current directory. To do this, execute the following command:
          cd Cs241 
  4. Make the new directory your Cs241 directory. To do this, execute the following command:
          mkdir Labs 
  5. Make the new directory your current directory. To do this, execute the following command:
          cd Labs 

Your instructors suggest using this directory hierarchy to stay organized. Now that you are in your Labs directory, you can copy the files you need for today's lab. Again, remember that you should use this procedure each time we have lab.

Continuing with UNIX Commands

  1. Get a long listing of your home directory by entering ls -l (remember that this command uses lowercase L's, not number 1's). Notice that there is now a subdirectory called Lab01.

  2. Get a long listing of what is contained in Lab01 (that's a zero-one at the end of Lab) by entering
          ls -l Lab01     

  3. Change the current directory to Lab01 by entering
          cd Lab01     
    Perform another ls once you get there.

  4. View the contents of a file, LabOne.java by entering
          more LabOne.java     
    To advance to the next page of the file, press the space bar.

1: When you reach a checkpoint, call over the instructor or lab assistant to check you off. Always be prepared to answer questions about what you have done. For this checkpoint be prepared to:
  1. Tell us why it is important to log off when done working.
  2. Tell us what the -r, / and . mean in the copy command you entered.

Sending a Program to a Second Account

While you and your partner work in lab each week, programs you work on during lab time will be saved in only one of the two accounts. Follow the steps outlined in your PreLab1 handout in order to copy the lab assignment to your partner's account.

2: Be prepared to answer the following questions:

  1. Why can't lab partners copy directly from one account to another account?
  2. Show us that the copy has been obtained by your partner.

Your partner may now log off, and partners should now go back to working together in one account.

Running the Firefox Web Browser

  1. Start running the Firefox web browser from Applications-Favorites-Firefox Web Browser in the top desktop display panel.

  2. Go to the CSCI-241 course website
          http://www.cs.uwp.edu/Classes/Cs241     

  3. Log on to Canvas by clicking the link from the course web page. Type your RangerMail id and password. Choose the CSCI-241 course and read the information at the top of the Announcements area. This page may be updated at any time! An email message to your RangerMail address will tell you when to check it.
3: Tell us the answers to the questions you found at the top of Canvas's Announcements area.

Working with BlueJ

Electronically Submitting and Printing a Programming Assignment

After almost every lab, you will get a new programming assignment for you to complete on your own. Each assignment is due one or two weeks after the lab on which it is based. It must be submitted both through your lab account and into Canvas. You must electronically submit your program(s) while running BlueJ in the lab. Your submission copies all files contained in your BlueJ project to a directory where your instructors can access and grade them. It will be in a subdirectory with your login name.

For practice, submit your BlueJ project named Lab01:

  1. Open a terminal (command) window and navigate (cd) inside the Lab01 folder.
  2. Perform an ls to make sure your LabOne.java file is here. If not, navigate to the project folder and check again.
  3. Once you are in the correct Lab01 directory, type submit LabOne.java and hit enter. A success message will be printed.
  4. Open a browser window and submit the LabOne.java file to Canvas for Grading.
  5. Close the window(s) when you are finished.
To verify that the submission worked, you can display the contents of what you copied to the screen by using this command (if your login name is smith):
     more /home/student/Submit/Cs241/smith/Lab01/LabOne.java
To practice printing, return to your editor window for the LabOne class. Choose Class-Print, then click OK to print a copy of LabOne.java. The printed copy will come out on the laser printer in MOLN D120, just outside the west doorway of the lab (MOLN D116), by our system administrator's office. The CS lab system will send you an email message each time telling you how many pages remain in your account.

4 Be prepared to answer the following questions:
  1. What does a BlueJ project hold?
  2. What are the basic differences between source code and byte code?
  3. Show your lab instructor or assistant that you have compiled this program and can run it.
  4. Show us your printout. Tell us how you will find out how many pages your account has in it before you need to buy more paper.

Now is a good time to trade keyboard and/or mouse control with your partner.

Creating your own Class

Now comes the real fun. You will create a complete Java class that implements an Etch-a-Sketch like program.
  1. Add a new class named Doodle to the project.

  2. Edit the class so that it appears almost exactly like that below (but with your own names, etc).
    /**
     *  Name: ____________ (login)
     *  Course: CSCI 241 - Computer Science I
     *  Section: ____
     *  Assignment: 0
     */
    
    import acm.program.*;
    import acm.graphics.*;
    import java.awt.*;
    import java.awt.event.*;
        
    public class Doodle extends GraphicsProgram
    {
        // instance variables
        private Point last;   // The previous position of the mouse
        private Color color;  // The color used for the drawing
        
        /**
         * Constructor for objects of class Doodle
         */
        public Doodle()
        {
             start();
             addMouseListeners();
             color = Color.BLACK;
        }
        
        /** 
         *  Called when the mouse is first pressed.
         */
        public void mousePressed(MouseEvent e) {
            last = e.getPoint();
        }
    
       /** 
        *  Called when the mouse is dragged.
        *  It creates a short line segment from the previous position to 
        *  this position.
        */
        public void mouseDragged(MouseEvent e) {
            Point pt = e.getPoint();
            GLine gline = new GLine(pt.x, pt.y, last.x, last.y);
            gline.setColor(color);
            add(gline);
            last = e.getPoint();
        }
        
        /** 
         *  Change the color for the next line drawn.
         */
        public void setColorBlue()
        {
            color = Color.BLUE;
        }
    }            
                
  3. Save this class by selecting "Class" and "Save". Note that there is a keystroke that you can use to do this instead (Ctrl-S). Your class is saved every time you use Ctrl-S.

  4. Compile the class, removing any errors that are detected.

  5. Create an instance of the class.
    To do this, right-click on the Doodle class and choose new Doodle(). Click OK on the next window that appears. WAIT for the newly created Doodle object will be displayed as a red icon on BlueJ's object bench.

  6. Draw a multi-colored picture. To draw, hold the left mouse button down while you move the mouse. It is up to you to figure out how to change colors.

5: Show your lab instructor or assistant that you have entered and compiled this program and can run it.

End of lab

Return to Firefox and log onto Canvas. Type your RangerMail id and password. Choose the CSCI-241 course and open the Assignments/Programming Assignments area to find your instructions for the first programming assignment. For this assignment, you'll use BlueJ to type in, edit, compile and run an already-written Java class. If you haven't already received one, ask your instructor for a paper copy of the program you will type in. This program will be due at the beginning of lecture, one week from today. You will need to submit it both electronically and on paper.

Each time you leave the lab, be sure to do the following:

  1. Log out of Firefox (if logged in).
  2. Log out of your account.
  3. Turn your monitor off.
  4. Push in your chair.
  5. Clean up any food, drink or other materials left on the wooden table near the printer.
6: Show us that you have logged out, cleaned up and pushed in your chairs for this last checkpoint.