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
- Make sure that you have
filled out, signed, and returned an account policy sheet.
- 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.
- 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.
- 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~]$".
- 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.
- 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.
- Open a terminal window. When you first open your terminal window,
you are placed in your home directory.
- Create a new folder for CSCI 241. To do this, execute the
following command:
mkdir Cs241
- Make the new directory your current directory. To do this,
execute the following command:
cd Cs241
- Make the new directory your Cs241 directory. To do this,
execute the following command:
mkdir Labs
- 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
- 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.
- 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
- Change the current directory to
Lab01 by entering
cd Lab01
Perform another ls once you get there.
- 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:
- Tell us why it is important to log off when done working.
- 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:
- Why can't lab partners copy directly from one account to another account?
- 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
- Start running the Firefox web browser from
Applications-Favorites-Firefox Web Browser
in the top desktop display panel.
- Go to the CSCI-241 course website
http://www.cs.uwp.edu/Classes/Cs241
- 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
- Make sure you are in your home directory by entering cd
and pressing Enter at the terminal window command line.
- Running BlueJ
Start running BlueJ by entering (after the $ prompt) the command
bluej&
Don't forget to type the ampersand (&).
- Open project Lab01
- Choose Project -> Open Project
- In the file dialog window that appears, double click on the Lab01 icon.
- Open class LabOne in the editor by right clicking on the icon and choosing
Open Editor.
So ... you may not have ever seen Java before, but this class is simple enough that
you should be able to figure out what it does. Examine the code in the file, but do
not change it. What do you think this program does?
- Compile this class.
Refer back to the prelab reading if you need a hint.
- Use your mouse to return to the black terminal window,
and enter the UNIX command
ls -l Lab01
See the two additional files in the
Lab01 subdirectory? LabOne.class holds the compiled
version of the class (translated into bytecode).
LabOne.ctxt holds information used by BlueJ.
- To run your compiled program, return to the
main BlueJ window and right-click on the class icon for LabOne.
Choose the line that says 'Run Main Method'.
- While running, the program will prompt you to enter two integer values.
Enter one value at a time by typing it at the end of the line, then
pressing Enter. After the program collects the two integers it
will display the result of dividing the first by the second.
Follow the directions and press Enter after each value.
Close the output and editing windows when you are done.
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:
- Open a terminal (command) window and navigate (cd) inside the Lab01 folder.
- Perform an ls to make sure your LabOne.java file is here. If not, navigate to the project folder and check again.
- Once you are in the correct Lab01 directory, type submit LabOne.java and hit enter. A success message will be printed.
- Open a browser window and submit the LabOne.java file to Canvas for Grading.
- 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:
- What does a BlueJ project hold?
- What are the basic differences between source code and byte code?
- Show your lab instructor or
assistant that you have compiled this program and can run it.
- 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.
- Add a new class named Doodle to the project.
- 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;
}
}
- 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.
- Compile the class, removing any errors that are detected.
- 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.
- 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:
- Log out of Firefox (if logged in).
- Log out of your account.
- Turn your monitor off.
- Push in your chair.
- 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.