Problem Solving Assignment 6



Due Monday, February 19 at 11:59pm PST


There are two problems in this PSA.

Notes:


This homework requires skills from Chapter 1 through Chapter 4 (objects), and 6.1 (arrays).


Problem 1

Write a program to keep track of contacts in a cell phone.

Introduction:

Details:

Hints:


Problem 2

Write a program that shows an animated demonstration of Galileo's famous Leaning Tower of Pisa experiment, with the wrong outcome.

Introduction:

Details:


Details

Making your psa6 directory

Start by creating a directory (folder) in your ieng6 cs8fzz account (this is necessary for the bundle-psa4 script). After you log in, create a directory by typing the commands:
-bash-2.05b$ mkdir psa6
Go into that directory (like double clicking to open a folder) with the command:

-bash-2.05b$ cd psa6 
Note: you must name your directories (folders) and files as indicated in the problem descriptions for the turn in program to work.

Running the sample solution program

In order to run the sample solution program you should invoke the following command:
-bash-2.05b$ runsample [classname]

To run a sample of GalileoUhoh, since it has graphics, you will need to do something different and run the class directly. Do:
-bash-2.05b$ cd ~/../public/
-bash2.05$ java GalileoUhoh

The to return to your own directory, do "cd ~/psa6".

Grading Criteria

This assignment is worth 20 points.

How to turn in your homework electronically

When you are ready to turn in your homework, run bundle-psa4 from your psa4 directory. The session should look like this:

-bash-2.05b$ cd ~/psa6
-bash-2.05b$ bundle-psa6
Good; all required files are present:

        ContactsList.java
	Circle.java
	GalileoUhoh.java

Do you want to go ahead and turnin these files? [y/n]y
OK.  Proceeding.


Performing turnin of approx. XXXX bytes 
Copying to /home/linux/ieng6/cs8w/turnin.dest/cs8wzz.psa6
.
Done.
Total bytes written: XXXX 
Please check to be sure that's reasonable.
Turnin successful.

If you want to make changes after you've turned in your homework, make the changes and run bundle-psa6 again. The program will warn you that a "previously turned-in file exists" and ask if "you wish to over-write this existing file" (delete the old version and replace it with this new one). Respond in the affirmative by typing y and pressing the Enter key.

Getting Your Interview Done

10% of your grade on this assignment will come from an interview you will have with one of the tutors during Open Lab Hours. You have 48 weekday hours after the electronic turnin deadline to get your interview done. The deadline for the interview for PSA 5 is Monday, Feb 19, theoretically at midnight, but actually by the end of the last tutor hour scheduled. You get an interview by going into B260 during a scheduled tutor hour. Find the tutor, ask them if you can interview for PSA 5. If they have others who are waiting for interviews, your name will go on the end of the list of people waiting. Interviews take about 5 minutes each. It is your responsibility to go in early enough that you can get your interview completed. If everyone waits until the last hour on Wed, this will not work. The tutor will ask you to log in, change to the directory where your work is (psa6) and then to follow their directions. They will ask you to run your program to show that it works, open files in your favorite editor, and ask you questions about how your code works. Additionally, they may question you as to how you would (theoretically) make small changes to the program to have it do something slightly different. Learning to be able to explain your problem solving process and discuss code with another human being is a very important professional skill. We hope that this process will help you develop this skill.

Unix Tips

Copying the assignment directory to partner's home directory

You can copy the psa6 directory and its files to your partner's home directory by:

bash% scp -r psa6 cs8wxx@ieng6.ucsd.edu:

(don't forget the colon at the end of the command) where cs8wxx is your partner's username. You must be in the parent directory of the psa4 directory. So, you if you are currently in the psa4 directory you should execute "cd ..". Similarly, if the psa6 direcory is in your home directory then you have to be in your home directory. If you aren't there just execute "cd ~" and you'll be there. Your partner is required to enter his password when you enter the scp command. To check if the copy worked, your partner must login and ckeck if the psa6 directory exists in his home directory and if the proper files are located in it. This can be done by executing: "ls ~/psa6". The files in the psa4 directory should be listed.

Redirecting the input and the output

You can redirect the input af a program by using the "<" symbol in the command line. Instead of reading the input from the standar input device (which is the keyboard):

bash% java MyProgram < sampleEmail.txt

This command will redirect the input of the MyProgram program to the file sampleEmail.txt. It will read the contents of the file as if they were given by pressing the buttons on keyboard. Similarly you can redirect the output af a program by using the ">" symbol in the command line. Instead of displaying the output on the standar output device (which is the computer monitor):

bash% java MyProgram > outFile.txt

This command will redirect the output of the MyProgram program to the file sampleEmail.txt. It will write the output in the "outFile.txt" file (all contents of the will be erased if file exists, if it doesn't exist, it will be created) as if they would be printed on the computer screen (so, you won't get any output on the screen). You can combine both redirections. For example you may have an email.txt file with a sample email, and also you want the results of the scan to be put on the file output.txt. This can be done by:

bash% java MyProgram < email.txt > output.txt

Finding the differences between files

You can find the differences between two text files by using the diff command:

bash% diff filename1 filename2

The output will be the differences between the files. If there is no output at all that means that the files are identical.

Example: Testing the output of your program, can be completed in four steps, using the above tips.

  • Create a file with sample input (lets name it "input.txt" for your program (as if you would write it if the program was running)
  • Run your program and redirect the exit to a file: bash% java Statistics < input.txt > output1.txt
  • Run the provided program and redirect the exit to a second file: bash% runsample Statistics < input.txt > output2.txt
  • Check if there are differences between the two output files: bash% diff output1.txt output2.txt
  • Learning to use text editors

    Vim

    Run the command vimtutor, a separate program that will teach you to use Vim.

    Emacs

    Use the built-in tutorial by running emacs and, within the editor, typing CTRL-h t.

    Pico

    You can reach Pico's built-in help by typing CTRL-g. If you want further instruction, look at this Pico tutorial from NC State.

    Use a real picture of the Leaning Tower of Pisa!

    After you are done with the basic GalileoUhoh.java assignment, follow these simple instructions:
    1. Make a new directory called psa6bonus:
      -bash2.05$ cd
      -bash2.05$ mkdir psa6bonus
      -bash2.05$ cd psa6bonus
    2. Copy a different version of the GalieloUhoh.java starter code into your directory:
      -bash2.05$ cp ~/../public/GalileoUhohBonus.java ~/psa6bonus
    3. Copy your Circle.java class (including the fall() method you added) into the psa6bonus directory:
      -bash2.05$ cp ~/psa6/Circle.java ~/psa6bonus/
    4. Open your original GalileoUhoh.java and copy the code that you added to that file. Paste it into the new one (GalileoUhohBonus.java) in the same place. The only thing different in the starter code is inside the "GUI stuff you can ignore" part at the top (and we changed the class name). So your part of the code should work just the same.
    5. Copy two files into your psa6bonus directory:
      -bash2.05$ cp ~/../public/GraphicsUtil.class ~/psa6bonus/
      -bash2.05$ cp ~/../public/LTP.gif ~/psa6bonus/
    6. Compile everything at once by doing: -bash2.05$ javac *.java
    7. Note: To run it, you do something just slightly different than normal (note the extra part in bold):
      -bash2.05$ java -cp . GalileoUhohBonus