CS 151 - Introduction to Data Structures

Lab 2

Unix

NOTE: This lab assumes that you at least made CS151 directories in lab last week (and Homework 1). If you have not done so, do that now. NOTE: Feel free to work in pairs.

Using Unix (actually Ubuntu Linux)


Some important UNIX commands:
If you are working from a personal laptop:
Open a connection onto goldengate with the following command (from a Mac Terminal or Windows Powershell). Note you can connect to goldengate from anywhere in the world using the exact command:
		ssh YOURUNIXNAME@goldengate.cs.brynmawr.edu
	
If you are working at a lab computer:
Open a terminal. To do so: click on the 3x3 grid of dots in the lower left, then scroll through screens until you find Terminal.
As the commands are explained below, try them out ... (below I use capitalization to try to show where the command name came from. The unix command themselves are always all in lower case.) Execute the above unix commands, put answers to the questions to their right
cd What directory are you in?  
What is the contents of this directory? (You need not list everything; 10 items is more than enough)  
cd / What directory are you in? (It has a special name.)  
What is the contents of this directory (again, 10 names is enough)?  
cd ~ What directory are you in?  
What is the contents of this directory?  
cd /home/YOU (Replace YOU with your login name) What directory are you in?  
What is the difference between this command and the previous one?  
ls /home/gtowell/Public/151 What did this command do?  
cat /home/gtowell/Public/151/L02/HW.java
cat /home/gtowell/Public/151/L02/HW.class
What did the second command do? Is the file HW.class readable? One sentence: explain.  
A good understanding of these few UNIX commands is about all you need to this course. (Many long-time Unix users know little more than these.)

Java Practice with inheritance

Write two classes "Older" and "Younger" such that Younger extends Older. (Feel free to rename.) Give Older two protected instance variables. Create a constructor in Older that sets the value of these two variables. Add a toString() method to Older. Finally, at least for Older, write a very short Main method that demonstrates all of what you just wrote.

Now write Younger. Give it two new protected instance variables. Write a constructor that initializes all 4 variables that are a part of Younger. Write a toString that shows all 4 instance variables in Younger. In your Younger toString method, use super.toString(). Write a main method to illustrate what you have done.

After completing all of the above, in your main within Younger add the line

		Older yo = new Younger(1,2,3,4);
		System.out.println(yo);
(Change the parameters to the Younger constructor as needed for your implementation.)

What gets printed in the added println? Explain.

What to hand in

Send email to gtowell@brynmawr.edu with the following:
  1. A completed table for the questions in the UNIX section
  2. If you worked with someone else, put both names in the subject line.
  3. Your Older and Younger implementations.
  4. Answers to the questions about Younger.
The easiest way to submit the Unix table might be to use your phone and take pictures of the completed hand-written, table. Alternately, if you typed your answers, just send them. These are just suggestions for how you could turn things in. Feel free to be creative. All I require is legibility.