Recitation 1


In this lab we'll be doing some exercises to refresh you on some basic programming constructs. We'll be doing some exercises with:

  • Loops
  • Arrays
  • Methods

Your focus task is to reverse an array. You will do it in several ways to illustrate several points about methods and parameter passing. Your main method should have code for testing your methods. For example, to test the reverse method you would do something like:

int [] test1 = {1,2,3,4,5,6,7,8,9,10};
int [] result1 = reverse(test1);
// add code to print the results 

Your java file should be named Recitation1.java (Notice that it begins with a capital letter!)

Part 1

Write a method called reverse that receives an array of integers as its input parameter and returns a reversed array of integers without modifying the original array.

Part 2

Write a method called reverseInPlace that reverses an array by swapping elements in the array. Is there an issue with arrays of odd or even length?

Part 3

Write a method called printStars that prints an ASCII triangle. Your method receives as input the number of rows/columns. For example, printStars(5) should print:

*****
****
***
**
*

Part 4

Create a data file called people.txt that contains a person's last name, a space, and their age. Data file listed below:

	Darby 92
	Coolie 18
	Jorge 25
	Jansen 40
	Geow 22

Read in the data file as a command line argument and store it into an array. Print out each line as follows: "Person : name, Age : #" For example, the first line would read "Person : Darby, Age : 92" Then print out all of the last names separated with a comma. For example, the output would be:

"Darby, Coolie, Jorge, Jansen, Geow" 

Assignment submission

TAs will go over the procedure for submitting programming assignments using the checkin program.


UNIX

Learning some of the basic UNIX commands for working in a UNIX/Linux environment can help you greatly. If you want to learn a lot about programming in the UNIX/Linux environment, you can take the course CS155 (1 credit). We will introduce you to some of the essential and most useful commands this semester.

Type the following commands at a terminal window. The TA will explain what each of them as you go along.

  • ls
  • ls -l
  • mkdir cs161Lab
  • ls
  • cd cs161Lab
  • pwd
  • cd ..
  • pwd

To obtain information on each command you can use the man command. For example:

   man pwd