Assignment #6 - Chapter 7 Exercises - Strings
Due: Friday, June 27
From chapter 7, do programming exercises
7.5, 7.6, and 7.7 (page 285).
Also note the extra instructions below.
Filenames should be
- Prob7_5.java
- Prob7_6.java
- Prob7_7.java
Note that these filenames all start with a capital letter. Please make
your filenames match mine exactly.
Extra Instructions
- For 7.5, write a main method to test your replace method.
The main method should prompt the user to type in the following three
strings, in order: an initial string, the string pattern being replaced,
and the replace pattern. Each of these inputs can be read in as a String
object with the readString method of the MyInput class
(same class used in previous assignments). The readString method
returns a reference to a String object. After the user input of
the strings, run the replace method and output the initial string and the
new string (see sample output)
-
Note that the Calculator example in the textbook (pg 281) contains an
example that also reads integer values off the command line. For problem
7.6 You will need to use the Integer class, and there is a method called
parseInt() that can convert a String of digits into an integer
representation.
- For 7.7, you may use the method isUpperCase(char ch) from the
Character class. See the
API specification for details.
Sample Outputs
Sample user input is underlined.
Sample output for 7.5
Programming Exercise 7.5 'Substring Replacing'
Input initial string: The quick brown fox jumped over the quick dog
Input substring to be replaced: quick
Replace with? hot
The initial string is 'The quick brown fox jumped over the quick dog'
The new string is 'The hot brown fox jumped over the hot dog'
Sample output for 7.6
(Note that the first line is the command to execute the program, from the
command prompt)
::> java Prob7_6 1 2 3 4 5
The total is 15
Sample output for 7.7
(Note that on the command line, placing quotes around something makes it a
single argument. Without quotes, each word is an argument).
::> java Prob7_7 "Java is Fun and So Says I"
The number of uppercase letters in 'Java is Fun and So Says I' is 5
Compiling
Remember that the compile command is "javac", at the unix command prompt.
Compile your code on program.cs.fsu.edu, and then run your programs with
the "java" command.
Submitting:
Submit programs through the submission web page.