Page 375 - Introduction to Programming with Java: A Problem Solving Approach
P. 375

                Sample session:
Enter width of desired square: 5
Area = 25
Exercises 341
 Print
Enter
#####
#####
#####
#####
#####
with (b)order or (s)olid? s
character to use: #
8. [after §8.6] Assuming it will be called by the draw method in the Square class in Figure 8.7a, write
a drawBorderSquare method that asks the user for two characters to use to draw a bordered square, one character of the border and a different character for the space in the middle. Notice that using the same character for the border and the middle makes this method draw a solid square, and thus this method makes the drawSolidSquare method redundant, although this method requires more user interaction.
Sample session:
Enter width of desired square: 5
Area = 25
 Print
Enter
Enter
BBBBB
BmmmB
BmmmB
BmmmB
BBBBB
with (b)order or (s)olid? b
character for border: B
    Apago PDF Enhancer
character for middle: m
9. [after §8.6] Figure 8.2b has two if statement conditions that contain what are called regular expressions. As indicated these are explained in the Java API Pattern class. This exercise is intended to help you get a better feeling for Java’s regular expressions and their usage. Use your Java API documentation on the Pattern class to get the answers to these questions:
a) What is the meaning of the regular expression, "[A-Z][a-z]*", which appears in Figure 8.2b?
b) What is the regular expression for a character string starting with a ‘Z’ and containing any number of
additional characters of any kind except for a space or a tab?
c) What is the regular expression for a string that represents a U.S. long-distance telephone number (three
digits, a dash or space, three digits, a dash or space, and four digits)?
10. [after §8.6] Define “stepwise refinement.”
11. [after §8.6] Write stubs for all the constructors and methods in the Student class of Figures 8.2a and 8.2b. Each stub should print out the method name followed by the initial (passed-in) values of all parameters, like this sample output:
in Student
in setFirst, first= Adeeb
in setLast, last= Jarrah
in Student, first= Heejoo, last= Chun
in printFullName
























































   373   374   375   376   377