University of Pittsburgh
  Spring 2004
CS0007:  Introduction to Programming
Assignment 1: What's my age again?
DUE DATE
Mon Jan 19, midnight
VALUE
20 pts
BACKGROUND
Ch 2 JBD
Edit, Run, Compile
Electronic Handin
Using the TIO Package

You will be turning this assignment in electronically.

It is essential that before you start, you have gone through the three handouts in the background.

Objectives

This assignment is intended to make sure you are up to speed on editing, compiling, using tio, and turning in programs.  You will also find out how to get a printout if you want one (although you will not be turning one in for this assignment).

What to do

First, study the programs on p. 25 (String concatenation) and p. 27 (User Input).  You should make sure you can compile and run both of these small programs. 

Your job is to write a new program that will ask for the user's name and age, read them into variables, then print this information back to the screen.  Here are some tips:
  • You'll need a string variable to hold the user's name and an int to hold the age.
  • You can obtain a string from the user by calling Console.in.readLine();  
  • Make sure you work in your java directory (private/java), you can use pwd to verify this. 
  • Use your favorite text editor (pico works) and name your program youridSayNameAge.java (plug in your unixs id where you see "yourid")
  • Make sure your class name (in the source file) matches this file name.
  • Java is case-sensitive, so, for example, "int" and "Int" are different identifiers. 
After you write your source code, compile, run, and debug if it necessary.  Again, it is very important that you have worked through the edit/compile/run and using tio handouts before you try to write this program. 

Sample Output

Here is an example of program execution.  Your output doesn't have to be exactly the same, but should be similar.

(36) unixs1 $ java youridSayNameAge
What is your name?  Snuffleupagus
What is your age?  4
Your name is Snuffleupagus and you are 4 years old.
(37) unixs1 $

Handing your work in

Before you do this, make sure you have gone through the handing programs in handout.  All of the key steps are shown there.  The only difference is that you will need to substitute the file name used in this assignment and the directory assignment1 for "sample".  Here are the steps you'll need to take, again substituting your CIS id for yourid.

(39) unixs1 $ ls -l youridSayNameAge.*
-rw-r--r--   1 yourid   OAKLAND      792 Aug 25 11:47 youridSayNameAge.class
-rw-r--r--   1 yourid   OAKLAND      541 Aug 25 11:47 youridSayNameAge.java
(41) unixs1 $ cp youridSayNameAge.* /afs/cs.pitt.edu/public/incoming/CS7-Lane/assignment1/
(42) unixs1 $ ls /afs/cs.pitt.edu/public/incoming/CS7-Lane/assignment1/yourid*
/afs/cs.pitt.edu/public/incoming/CS7-Lane/assignment1/youridSayNameAge.class
/afs/cs.pitt.edu/public/incoming/CS7-Lane/assignment1/youridSayNameAge.java
(43) unixs1 $

(41) does the actual copy and (42) is a way for you to confirm that the files are actually there and turned in.  If you run into an error, you may have mistyped the full path name or have files in the handin directory with the same name.  It is important you do not misuse the copy command - be very careful to type things in correctly. 

Getting a Printout

Sometimes it is useful to have a printout (although not required in this assignment).  When you come for help from the instructor or TA, you must bring a printout  (we'll be writing on it).  There are several ways to obtain one:


Printing from unixs

You can get a printout in most of the campus labs, you just have to know the code (aka, "queue name) for the lab you want.  For example, the following command will print from the Benedum 10th floor lab:

(8) unixs1 $ lpr -PBEH youridSayNameAge.java
BEH is the code for Benedum hall.  You can pick up the printout about 15 minutes later at the main desk.

Here is a list of some of other labs.  Just substitute these codes in for BEH above if you want to use them:

  • CL:  G-27 Cathedral of Learning
  • DLH: 230 Lawrence Hall
  • FQ: 1E01 Posvar Hall
  • HL:  G82 Hillman Library
If you need another lab, just ask a lab attendent, or check at the Pitt Technology web site.

If you aren't working in a lab, then you need a way to get your source code file to your local machine for printing.

Cutting & Pasting

The simplest way is to do a cut and paste from your telnet session.  Just highlight the program code on your screen, select copy (Ctrl-C often works), open up notepad (or any editor), then paste (Ctrl-V often works).  You can print from there.  If your program is large, this is not a great way to go.


Emailing the code to yourself

If you are familiar with a unix email program (like pine or elm), you can start this up in unixs (be in the same directory as your code), and email the code to yourself as an attachment.  You can simply print the email, then. 

Here is a handout describing how you can do this with pine.


ftp

Even if you aren't familiar with ftp, you can use this method.  One a windows computer, just do Start --> Run --> and enter ftp unixs.cis.pitt.edu  Then enter your user id and password.  From here you can cd your way to your java directory, then type get <filename> (plug in whatever file you want).  ls works as well, so you can look before you get.  This will download the file to your computer (you'll have to find it).  If you have another FTP program available (like WS_FTP), you can use it as well)


Last Updated: 1/12/04
by H. Chad Lane