130 likes | 202 Views
CSE 1020:Software Development. Mark Shtern. Summary. Error handling String Handling The masquerade and the + operation Applications Character Frequency Character Substitution Fixed-Size codes Variable-Size code StringBuffer. Exercise 6.15.
E N D
CSE 1020:Software Development Mark Shtern
Summary • Error handling • String Handling • The masquerade and the + operation • Applications • Character Frequency • Character Substitution • Fixed-Size codes • Variable-Size code • StringBuffer
Exercise 6.15 Write a program that reads a string and outputs its length exclusive of any trailing asterisks For example, if the user entered “java**” the output should be 4 If the user entered “**” the output should be 0
Exercise 6.18 Write a program that reads a string and corrects one aspect of its spelling as follows: The letter pair “ei” is replaced by “ie” unless it is preceded by c For example, “BELEIVE, seive, conceive” becomes “BELIEVE, sieve, conceive”
Pattern Matching • Pattern matching problems: • Determine whether a given string is made up of two words • Determine whether a given string contains an integer surrounded by letters and separated from them by whitespace
Regular expression • It is a string that describes a pattern in a formal fashion • Pattern example: • "((0[0-9])||(1[0-2])):[0-5][0-9] [ap]m “ time
Character Specification • Range • [a-m] • Union • [a-m[A-M]] • Set • [abc] • Negation • [^abc] • Intersection • [a-m&&[^ck]]
Predefined specification • Any character • . • A digit • \d • A whitespace character • \s • A word character • \w • A punctuation character • \p
Quantifiers • x, once or not at all x? • x, zero or more times • x* • x, one or more times • x+ • x, at least n but not than m times • x{n,m}
String class • Methods • matches • replaceAll • split
Command-Line Arguments • Application launches as following • java <class name> <arg1> <arg2> <arg3> • Access to command line arguments • arg[0] arg1 • arg[1] arg2 • arg[2] arg3
Exercise 6.22 • Write a program that reads a DNA sequence from the user and determines whether it is valid • To be valid it must: • Contain only the letters A C G T • Start with ATG • Have a character count that is a multiple of 3