CS102 Lab1


In this lab you will get used to the UNIX/solaris environment on the eagle server and shake the rust off of your programming skills.


The high level objectives of this lab are:

What you must do:

Java can, in theory, be programmed on any machine with any operating system and the program will run on any other system. However, in practice there are sometimes strange incompatiblities when moving from one system to another. Eagle is the canonical system for this class. You may program your assignment anywhere you like, but it must run on eagle. I will run all of your programs and if they do not run on eagle, you will lose points from your assignment. To that end, the beginning of this lab is intended to get you used to working on eagle.

Once you have received your cs 102 account for the semester, you must first set the password. To do that use a telnet program and connect to eagle. You should only telnet this first time. You must used telnet from on campus. Because it is an insecure protocol, it is no longer available from off campus. Once your password is set, log out.

Now use ssh to log in. ssh is the “secure shell”. It is much more secure than telnet and will give some nice features that we will use later in the class.

Ssh is available built in on Macs and Linux/Unix computers. For windows users there is a free program called putty that you can download and install to give you ssh capability. (see http://www.chiark.greenend.org.uk/~sgtatham/putty/ for the putty home page.)

Or you can use the CD for windows that I gave out in class.

now log into eagle.

ssh <usename>@eagle.bridgew.edu (where you must replace <username> with your actual eagle username)

Now copy two configuration files. Type (or paste in) the following commands

cp /export/spare/faculty/jsantore/.tcshrc-cs102 .tcshrc
If you are typing the line, note that there is a space between -.tcshrc-cs102 and .tcshrc

cp /export/spare/faculty/jsantore/.profile .
Once again, if you are typing this, make sure that you put a space between the .profile and the final '.' character. The final . character means that

Your Program:

In this lab you will write a lottery simulator. Your program will query the user for the kind of lotto game to play and will ask the user how many chances the user wants to buy. The program will then generate the lottery number and see if the user has won. The program will finally report to the user how much money the user has lost or won.


For simplicity, we will limit the games to a "pick three" and a "pick four" styles of game. For these games players choose three numbers from a range. We will run a *very* generous lottery and limit the range of numbers to those from 1 to 25. We will allow duplicate numbers in this lab to make things easier on you.

Your program must

Sample Output:

Here is some sample output from my solution to this problem. You may have something that looks somewhat different and that is fine so long as the requirements above are met.

cicero {~/teaching/Spring2006/cs2/lab1} >java App
Play a pick four game?
(enter Y to play pick four, anything else for pick 3)
How many chances do you want to buy?
Your bets:
[[10, 6, 16, 9], [14, 4, 2, 12], [3, 16, 16, 16], [3, 6, 16, 10], [18, 20, 7, 15]]
The winning numbers were:
[3, 7, 2, 24]
Your net income from playing the lottery: -5 dollars
cicero {~/teaching/Spring2006/cs2/lab1} >java App
Play a pick four game?
(enter Y to play pick four, anything else for pick 3)
How many chances do you want to buy?
Your bets:
[[1, 25, 11], [2, 15, 23], [16, 5, 12], [19, 23, 14], [19, 23, 12], [10, 23, 15], [23, 22, 24], [17, 9, 12]]
The winning numbers were:
[21, 8, 13]
Your net income from playing the lottery: -8 dollars

Writing your program

To write your program you will need to use an editor. In the past many students have written their programs using notepad as their editor and then used ftp to move the file to eagle. This was done because the tools available on eagle at the time were rather limited. I suggest you write your code on eagle itself after connecting through ssh using the CD that I gave you in class.

If you have high speed internet - especially from school:

Users who have fast connections should probably use emacs. It is the most full-featured of the editors. To run emacs, type

emacs <filename.java> &

where <filename.cpp> is the cpp file you want to edit.You will have an emacs window popup on your screen and you will be able to use menus normally. This editor also "pretty prints" your text using colored text for java keywords and constants. It will also indent your text for you properly giving you a better feel for your program. You will get a java menu that allows you to compile your program directly from emacs rather than returning to the command line.

The '&' character means "run this in the background". In plain english than means "give me my prompt back after you run this program"

If you have slower speed connections - mainly off campus

Use xjed, which will also displays keywords in color and indents text. It doesn't have quite as much functionality and isn't as pretty, but it is faster.

xjed <filename.java> &

When you are ready to try compiling what you have written

Pull your emacs or xjed window out of the way and use javac to compile files. Use java with the name of the class that contains the main method to run your program.


When your program is ready, you need to write a readme.txt file that provides me the following information:

If you are in your lab1 directory when you read this, move to the parent folder/directory
cd ..
(where the '..' means <parent directory> note that there is a space between cd and ..)
now zip up the entire lab1 directory and send it to me.
zip -r lab1.zip lab1
This means zip up the entire lab1 directory (the -r flag says do everything in the directory not just the directory itself) and put it in a file called lab1.zip

Now prepare to email your lab to me.

type the following command
Pine is a terminal based email program. From eagle, you will only be able to send mail to bridgew.edu email addresses. You will submit your lab by email to me this semester. However you need to configure pine the first time you use it.

Configuring pine

Choose 'c' to compose a mail and send me a mail with the zip file of your lab solution attached.