There are two problems in this PSA.
Notes:
This IS a pair assignment. You MUST do the assignment with your partner.
You must complete an interview with a Lab Tutor for this PSA. Interviews are individual (partly to ensure that one partner doesn't do all the work). See instructions here for more details.
This work should be done in its own directory called 'psa4'. Instructions here.
This assignment has sample solution code that you can run on ieng6. You won't be able to see the java code itself =) but you will be able to do tests to see what it does, and make sure yours does the same thing. YOUR CODE MUST DO THE EXACT SAME THING. EXACT!! Wording, spaces, everything. Instructions on how to run the sample solution code are here .
Each file must have a header with the team members' names, logins, and PIDs. The header should also describe the program in 2-3 sentences.
This homework requires skills from Chapter 1 through Chapter 3.
Write a Caesar Cipher secret code system.
key to "lock" and "unlock" the message. This should be a whole number between 1 and 25 (inclusive) (plus hitting "ENTER"). To decrypt a message, the user provides the same key value that encrypted it. Again, you need to chastise the user if the key is not between 1 and 25. (keep chastising and re-asking until you get a valid key) (Note: you can assume that the user enters some integer, you are just checking the value. You will need to do an "extra" scanner nextLine() to get rid of the "ENTER" as shown on pg. 81 of your book, line 24 of the code example)
key the user entered is how many times to shift the alphabet.
key, you will shift all letters by 3, with wraparound. So A becomes D, B becomes E, and so on up to W, which becomes Z. Then the sequence wraps around: X becomes A, Y becomes B, and Z becomes C. (that's why 25 is the maximum value for they key--26 would just shift it back to A = A, B = B, etc).
key the user entered to be a value that will rotate the alphabet back to the original. Then continue with your regular encryption procedure. (Big hint: remember that 26 total rotations takes you back to start.)
key=3) is not 28! All offsets should be in the range of 0-25. "Wrapping back around" will involve determining when you have "gone over then end" and then finding out the "left over amount" you have gone over then using that amount to offset from the beginning of the alphabet.
Write a virtual Etch-A-Sketch picture-drawing program.
-bash2.05b$ cp ~/../public/EtchASketch.java ~/psa4/
Your code will all be inside a method called "run" instead of the usual "main". Don't worry about the other code in the file, just leave it alone. It is ok if you don't understand what it is doing. So, inside the "run" method, you should do the following:
turtle.forward(double);
turtle.left(double);
turtle.right(double);
turtle variable is not declared anywhere in your run() method. Don't worry, we took care of that for you already, somewhere else in the provided code.
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:Go into that directory (like double clicking to open a folder) with the command:-bash-2.05b$ mkdir psa4Note: you must name your directories (folders) and files as indicated in the problem descriptions for the turn in program to work.-bash-2.05b$ cd psa4
In order to run the sample solution program you should invoke the following command:
So for this assignment, do:-bash-2.05b$ runsample [classname]
or-bash-2.05b$ runsample TopSecret
-bash-2.05b$ runsample EtchASketchTo see a sample solution WITH graphics, you can do:
-bash2.05$ cd ~/../public
-bash2.05$ java EtchASketchTo go back to your own directory after you are done, do
-bash2.05$ cd ~/psa4/To see a sample solution with NO graphics, you can do:
-bash2.05$ runsample EtchASketchMinimalThis will run a version of the sample solution that is exactly like the real one in terms of all the user interaction and input from the user but has NO GRAPHICS. It just has little placeholder S.o.p() statements like "[moving turtle left 20 degrees]" and so on. This is useful if you want to do SOME work from home, then come to lab to make sure the graphics part is working.
This assignment is worth 20 points.General (4 pts):
- 1 Point: For proper formatting. Your code is properly and consistently indented.
- 1 Point: For documentation. You must write a 2-4 sentence description of the program (as a comment) that provides insight into what the program does and what it's useful for. In this header comment, you are also required to put the author names, author PIDs and author logins
- 2 points: Interview (done individually) see instructions here.
TopSecret.java (8 pts):
- 2 points: Correctly input encrypt/decrypt (including chastising)
- 2 points: Correctly input
key(including chastising)- 3 points: Correctly output encrypted message
- 1 points: Correctly output decrypted message
- Everything must match the sample solution exactly.
EtchASketch.java (8 pts):
- 2 Points: Correctly check user's main menu choice (including chastising)
- 2 Points: Correctly check user's distance and degree choices (including chastising)
- 1 Point: Correctly move turtle left
- 1 Point: Correctly move turtle right
- 1 Point: Correctly move turtle forward
- 1 Point: Correctly end game
- Everything must match the sample solution exactly.
When you are ready to turn in your homework, runbundle-psa4from yourpsa4directory. The session should look like this:-bash-2.05b$ cd ~/psa4 -bash-2.05b$ bundle-psa4 Good; all required files are present: TopSecret.java EtchASketch.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.psa2 . 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-psa4again. 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 typingyand pressing theEnterkey.
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 3 is Wednesday, Jan 31, 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 3. 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 (psa4) 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.
Copying the assignment directory to partner's home directory
You can copy the psa4 directory and its files to your partner's home directory by:(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
bash% scp -r psa4 cs8wxx@ieng6.ucsd.edu:"cd ..". Similarly, if the psa4 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 psa4 directory exists in his home directory and if the proper files are located in it. This can be done by executing:"ls ~/psa4". 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):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 < sampleEmail.txtThis 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 > outFile.txt
bash% java MyProgram < email.txt > output.txtFinding the differences between files
You can find the differences between two text files by using thediffcommand:The output will be the differences between the files. If there is no output at all that means that the files are identical.
bash% diff filename1 filename2Example: 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.txtRun the provided program and redirect the exit to a second file: bash% runsample Statistics < input.txt > output2.txtCheck if there are differences between the two output files: bash% diff output1.txt output2.txt
Vim
Run the commandvimtutor, a separate program that will teach you to use Vim.Emacs
Use the built-in tutorial by runningemacsand, within the editor, typingCTRL-h t.Pico
You can reach Pico's built-in help by typingCTRL-g. If you want further instruction, look at this Pico tutorial from NC State.