CS 110 >> Introduction to Computer Science
Spring 2020
Lab Assignment 07
T OPICS


Importing Java Projects
Using the Eclipse Debugger


Setting BreakPoints
Stepping though execution in Debug
I NSTRUCTIONS
Complete the problem by importing the Java project and debugging the project until it performs the specified
action. You may use any IDE you wish but the instructions assume you are using Eclipse. This assignment will
cover importing Java projects and using the Eclipse Debugger.
IMPORTANT: Complete the below steps in the order they are given. Completing the steps out of order may
complicate the assignment or result in an incorrect result.
P ROBLEM 1
For this problem, we are going to learn how to find bugs in an algorithm for counting the syllables of a
word.
Lab 7 project contains two files, a Word.java file and CountSyllables.java. The Word class uses this rule
for counting syllables: Each group of adjacent vowels (a, e, i, o, u, y) counts as one syllable (for
example, the “ea” in “peach” contributes one syllable, but the “e . . . o” in “yellow” counts as two
syllables). However, an “e” at the end of a word doesn’t count as a syllable. Each word has at least one
syllable, even if the previous rules give a count of 0.
Also, when you construct a word from a string, any characters at the beginning or end of the string that
aren’t letters are stripped off. That is useful when you read the input using the next method of the
Scanner class. Input strings can still contain quotation marks and punctuation marks, and we don’t
want them as part of the word.
Your task is to find and correct the errors in this program.
1. Import Lab 7 project which contains two files: Word.java and SyllableCounter.java.
2. At the top of your .java files, add the following documentation comments
// Your Name
// CS110 Section XX
// Assignment XX
// Todays Date
3. Run SyllableCounter.java and supply this input in the console: Hello yellow peach.
Note the output:
Syllables in Hello: 1
rev. February 26 – 1 / 6
Syllables in yellow: 1
Syllables in peach.: 1
4. Set a breakpoint in the method signature line of the countSyllables method of the Word class
(public int countSyllables()). See Figure 1: Example Breakpoint in Eclipse.
H INT : P RESS CTRL + SHIFT + B TO SET A BREAKPOINT .
Figure 1: Example Breakpoint in Eclipse
5.
Start the program in debug mode.
H INT : P RESS F11 ON YOUR KEYBOARD TO RUN IN DEBUG PERSPECTIVE .
6.
The program will prompt you for the input in the console. Supply the input from step 3 again
and press enter. The program will stop at the breakpoint you just set. First, the countSyllables
method checks the last character of the word to see if it is a letter ‘e’. We will verify that this
works correctly. Run the program to the line if (ch == ‘e’ || ch == ‘E’) { end–;
} by using the step over function.
H INT : P RESS F6 ON YOUR KEYBOARD TO STEP OVER .
7. Now inspect the variable ch. The Eclipse debugger displays all of the current local and instance
variables— see Figure 2: Example Debugging Session. If you cannot see the variables, you may
need to open the variables perspective. In your debugging session, you should see that ch
contains the value ‘l’.
Figure 2: Example Debugging Session
2/6
CS 110 >> Introduction to Computer Science
Spring 2020
Lab Assignment 07
8. Look at the source code. The end variable was set to text.length() – 1, the last position in
the text string, and ch is the character at that position. Looking further, you will find that end is
set to 3, not 4, as you would expect. Also, text contains the string “Hell”, not “Hello”. Thus,
it is no wonder that countSyllables returns the answer 1. We’ll need to look elsewhere for
the error.
9. Next, we will inspect the Word constructor to see if it contains an error. Unfortunately, a
debugger cannot go back in time. Thus, you must stop the debugger.
H INT : PRESS CTRL + F2 TO STOP THE DEBUGGING SESSION .
10. Set a breakpoint in Word.java on the line that contains the signature for the Word constructor
and restart the debugger.
11. Supply the input once again. The debugger will stop at the beginning of the Word constructor.
The constructor sets two variables i and j, skipping past any nonletters at the beginning and the
end of the input string. Set a breakpoint past the end of the second loop (text =
s.substring(i, j);) so that you can inspect the values of i and j.
12. At this point, inspecting i and j shows that i is 0 and j is 4. That makes sense—there were no
punctuation marks to skip. So why is text being set to “Hell”? Recall that the substring method
counts positions up to, but not including, the second parameter. Thus, the correct call should
be text = s.substring(i, j + 1); This is a very typical off-by-one error.
13. Fix this error, recompile the program, and try the three test cases again. You will now get the
output shown in Figure 3: Debugging Session After Step 12.
Figure 3: Debugging Session After Step 12
14. As you can see, there still is a problem. Erase all existing breakpoints and set a breakpoint in the
countSyllables method.
rev. February 26 – 3 / 6
15. Start the debugger and supply the input “Hello.”. When the debugger stops at the
breakpoint, start single stepping through the lines of the method. Here is the code of the loop
that counts the syllables:
boolean insideVowelGroup = false;
for (int i = 0; i = 0)
{
// ch is a vowel
if (!insideVowelGroup)
{
// Start of new vowel group
count++;
insideVowelGroup = true;
}
}
}
16. In the first iteration through the loop, the debugger skips the if statement. That makes sense,
because the first letter, ‘H’, isn’t a vowel. In the second iteration, the debugger enters the if
statement, as it should, because the second letter, ‘e’, is a vowel. The insideVowelGroup
variable is set to true, and the vowel counter is incremented. In the third iteration, the if
statement is again skipped, because the letter ‘l’ is not a vowel. But in the fifth iteration,
something weird happens. The letter ‘o’ is a vowel, and the if statement is entered. But the
second if statement is skipped, and count is not incremented again. Why? The
insideVowelGroup variable is still true, even though the first vowel group was finished when
the consonant ‘l’ was encountered. Reading a consonant should set inside VowelGroup back to
false. This is a more subtle logic error, but not an uncommon one when designing a loop that
keeps track of the processing state. To fix it, stop the debugger and add the following else
clause:
if (vowels.indexOf(ch) >= 0) {
// ch is a vowel
if (!insideVowelGroup) {
// Start of new vowel group
count++;
insideVowelGroup = true;
}
} else {
insideVowelGroup = false;
}
4/6
CS 110 >> Introduction to Computer Science
Spring 2020
Lab Assignment 07
17. Now recompile and run the test once again. The output is shown in Figure 4: After debugging.
Figure 4: After debugging
Is the program now free from bugs? That is not a question the debugger can answer.
Remember: Testing can show only the presence of bugs, not their absence.
S UBMISSION
Any questions about the assignment itself or errors you may find in your code can always be addressed
towards myself via email or in-person. You will create a zip file containing Word.java, and
SyllableCounter.java named lab7.zip and submit lab7.zip to eCampus when complete.
This assignment is due before the next class on Wednesday, March 4, 2020 by 3:00 PM for section 002.
This assignment is due before the next class on Thursday, March 5, 2020 by 6:30 PM for section 003.
M AKE SURE TO SUBMIT THE . JAVA FILE AND NOT THE . CLASS FILE WHEN SUBMITTING YOUR WORK . I F
YOU SUBMIT THE . CLASS FILE YOU WILL RECEIVE NO CREDIT .
G RADING R UBRIC
This assignment is worth 20 points. It will be graded by your instructor using this rubric:
Criteria
Program source
file is
documented
correctly
Excellent
Good
Fair
Poor
Unsatisfactory
(4 points)
(3 points)
(2 points)
(1 point)
(0 points)
Program
source file is
missing one
required
comment
Program
source file is
missing less
than half of
the required
comments
Program source
file is not
missing any
required
documentation
Program
Program source
source file is
file contains no
missing most
documentation
of the
documentation
rev. February 26 – 5 / 6
Program source
file follows
coding
standards
Program follows Program
all coding
follows most
standards
coding
standards
Program
follows some
coding
standards
Program
follows only a
few coding
standards
Program does
not follow any
coding standards
Program Output
Program output
meets
instructional
requirements
with no errors
Program
output meets
most
instructional
requirements
with minor
errors
Program
output meets
some
instructional
requirements
with moderate
errors
Program
output meets
only a few
instructional
requirements
with major
errors
Program output
does not meet
any instructional
requirements
Program
execution
performs
according to
assignment
specifications
Program
executes
correctly with
no syntax or
runtime errors
Program
executes with a
minor error
(one easily
fixed error)
Program
executes with
moderate
error (few
easily fixed
errors)
Program
executes with
major errors
(significant
revision to fix
error)
Program does
not execute
Program is wellorganized and is
highly readable
Program is
stylistically well
designed
Few
inappropriate
design choices
(i.e. poor
variable
names,
improper
indentation)
Several
inappropriate
design choices
(i.e. poor
variable
names,
improper
indentation)
Program is
poorly written
Program
contains no
organization
S OURCES
Instructions from Worked Example 6.3 http://bcs.wiley.com/hebcs/Books?action=resource&bcsId=7872&itemId=1118431111&resourceId=30501
6/6

Purchase answer to see full
attachment




Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.