This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 15-121 FALL 2009 (Reid-Miller)HOMEWORK 1* - due Thursday, September 3 by 11:59PMPROBLEMS (10 pts)For each of the following problems, write up your answers in a plain-text (ASCII) file. Do not use Word (.doc) or Rich Text Format (.rtf).You should write any code answers without the aid of a compiler to practice solving written problems on paper. After you are satified with your answer, you may test it on the computer, if you wish. 1. (2 pts) Write a Java method that accepts two strings as parameters and returns a string that contains all uniquetwo-character strings whose first character comes from the first string and second character comes from the second string. All two-character strings in your returned string should be separated by commas (i.e. the comma is used as a delimiter). Use ordinary string concatenation in your solution. Examples: First string Second string Returned stringABCD EFGH AE,AF,AG,AH,BE,BF,BG,BH,CE,CF,CG,CH,DE,DF,DG,DHACDC ABBA AA,AB,CA,CB,DA,DB2. (1 pt) In the previous problem, if the length of the first string is m and the length of the second string is n, what is the maximum length of your returned string in terms of m and n? What condition is required to get the maximum number of two-character strings? 3. (1 pt) Rewrite your answer to #1 using a StringBuilder. 4. (1 pt) Compare your answers for #1 and #3. Which will run faster in general? Why? 5. (2 pts) A string consists of a series of names separated by commas, as shown in the example below: TOM,MARGARET,DAVE,TIM,BARBARA,VICTOR,ANGIE,MARK,SCOTTWrite a method that takes a string of comma-delimited names as a parameter and prints out the names in the string, one per line using a Scanner. (HINT: The Scanner class has a useDelimitermethod that will be helpful.) 6. (2 pts) Write a Java method that requires a String parameter that contains the name of a text file that contains one integer per line. Your method should try to open the file and compute and return the sum of all of the integers in the file. If the file cannot be opened, return 0. You may assume that if the file can be opened, it contains only one integer per line, with no other text. 7. (1 pt) Write a Java method that has a parameter referencing an array of integers. The method should return the maximum value stored in the array. PROGRAMMING PROJECT (10 pts)The following cryptographic system was used years ago to encode messages for security purposes....
View Full Document
- Spring '09
- Cryptography, Latin alphabet, Lower case, key phrase