Anda di halaman 1dari 4

CS E214

Practical 5 2012
Complete the following questions from the Exercises section in the textbook, Introduction to Programming in Java. Resources for certain questions, such as code libraries you are asked to use and example input and output les which can be used for development of your programs can be found on the course website. You have to hand in your answers to these questions. In order to keep all the les in one place you have to tar your les. A quick tutorial on tar is given below.

Tar how-to
We use tar to archive multiple les in one le for convenience. For more information on tar see the man pages: man tar To create a tar archive: tar cvf archive.tar file1 file2 file3 To extract the les contained in a tar archive: tar xvf archive.tar You must use the format <student#> prac<prac#>.tar for your tar le name. Hand-in date: 23:59 Sunday 11 March 2012.

3.1.15 [Optional]

Circular shifts. Application: computational biology. A string s is a circular shift of a string t if its characters can be circularly shifted to the right by some number of positions, e.g., actgacg is a circular shift of tgacgac, and vice versa. Write a program CircularShifts that checks whether one string s is a circular shift of another t. This can be accomplished by a one-liner if indexOf and string concatenation are used. Both strings must be read from standard input. Some example input and the corresponding output are provided on the course website.

3.1.17 [20]

Write a static method reverseDomain that takes a domain name as an argument and returns the reverse domain name (reverse the order of the strings between the periods). For example, the reverse domain of cs.sun.ac.za is za.ac.sun.cs.

3.1.19 [20]

Modify P ROGRAM 3.1.8 GeneFind to handle all three stop codons (instead of handling them one at a time through the command line). Some sample genomes can be found on the course website. Count the number of genes that you nd. Draw a histogram of the lengths (expressed in codons) of the genes (how many genes did you nd between 1 and 10 codons in length, between 11 and 20 condons, and so on). Use your program to nd the number of genes in human chromosome 11. Dont print out the chromosome or the genes that you nd! Do a web search on human chromosome 11. See what some of the genes code for, and see some of the diseases that are caused if both copies of a particular gene are damaged. Do you suspect that there is something wrong with your input le chromosome11.txt? What is wrong? How many genes are there in the human genome? Why are you nding so many genes?

3.1.31 [20]

The Kama Sutra cipher. Write a lter KamaSutra that takes two strings as command line arguments (the key strings), then reads a plain text from the standard input, substitutes each letter of the plain text as specied by the key strings to produce a cipher text, and writes the cipher text to the standard output. This operation is the basis for one of the earliest known cryptographic systems. The condition on the key strings is that they must be of equal length and that any letter in the plain text must be in exactly one of the key strings. For example, if the plain text is all in capital letters and the key strings are THEQUICKBROWN and FXJMPSVLAZYDG then we make the table THEQUICKBROWN FXJMPSVLAZYDG which tells us that we should substitute F for T, T for F, H for X, X for H, and so on when encoding the plain text to cipher text. The message is encoded by replacing each letter with its pair. For example, the message MEETATELEVEN is encoded as QJJFBFJKJCJG. The recipient of the message can use the same keys to decode the message.

3.1.32 [20]

Safe password verication. Write a static method that takes a string as argument and returns true if it meets the following conditions, false otherwise at least eight characters long contains at least one digit [0-9] contains at least one upper case letter [A-Z] contains at least one lower case letter [a-z] contains at least one character that is neither a letter nor a number.

3.1.38 [Optional]

Rotation lter. Write a program Rotation that takes two command-line arguments (the name of an image le and a real number theta, ) and rotates the image degrees clockwise. For each target pixel (ti , tj ) you have to copy the colour of a pixel (si , sj ) in the source image. The following formulas can be used: ti tj = = (si ci )cos() + (sj cj )sin() (si ci )sin() + (sj cj )cos()

Here (ci , cj ) is the center of the image and is the angle of rotation (counter-clockwise).

3.1.39 [20]

Swirl lter. Write a program Swirl that implements a swirl effect similar to the rotation, except that the angle changes as the function of distance to the center. Use the same formulas as in the previous exercise, but compute as a function of (si , sj ), specically /256 times the distance to the center.

(a) Original

(b) Rotate 30 degrees

Figure 1: Baboon on a merry-go-round

(a) Original

(b) Swirl lter

Figure 2: Baboon sucked into a black hole

Anda mungkin juga menyukai