02 Cbtest
02 Cbtest
Learning Outcomes
By the end of the lab exercise, you will be able to:
• Analyze a piece of source code to determine what it does
• Construct multiple sets of input values that will cause a program to work correctly and
incorrectly
• Interpret compiler error messages in order to learn how to correct them in the future
Preamble
For this lab, you are to work together in groups of two (wherever possible). Brightspace has
already broken you into groups. Find your partner, introduce yourself and decide on how to
proceed with the lab. I’d suggest the two of you use the same computer and keyboard/mouse;
it’s a technique called “pair programming”, where one of you gives directions and the other does
the typing. It’s like being in a car where one person is the driver and the other is giving
directions (navigating). Remember to switch roles periodically. The TA and I will be circulating
to check on your progress.
You may use any Java compiler for this lab.
Lab Activities
1. Download the cbTest program and get it to run. This program has one intentional error in
it. Find it and correct it, so that your program actually runs, instead of producing a syntax
error message.
2. Update the program’s identification sections.
a. Scan through your program to find the definition of the method
printIdentification(), (roughly line 30) which should contain all the names and
student numbers of those working on this lab. Fix the code here according to the
directions within the source code.
b. Then, again as a comment at the top of the source code, please also fill in the
names and student numbers of all those working on the lab together.
3. Copy and paste the following questions into a word processor. Keep the word processor
open and at the same time run the program with the following sets of experiments. Write
down your answers to each question. Save your work often.
(a) Try several pairs of numbers to determine what the program actually accomplishes.
Report the computer’s outcome for each pair. Finally, for one of the pairs, explain in
detail exactly how the computer obtains the answer that it does.
(i) 45, 7 (ii) 92, 2 (iii) 65, 8 (iv) 34, 3 (v) 125, 5
(b) Now, find out experimentally, all the kinds of values for which it does not run
correctly? Give explicit answers.
1
LANGARA COLLEGE
COMPUTER SCIENCE 1150
(c) In the conv() method there are several identifiers with meaningless names. Think up
better names. List the original (bad) name and your better name and explain why
your names are better.
(d) What is the actual purpose of this program? (That is, what does the whole thing
accomplish/do?) If you need more sets of values than were listed earlier to figure out
the program’s purpose, then go ahead. Now would be a good time to go and modify
the printInstructions method (roughly line 40) so that it actually prints out what the
program does!
Note: In the remaining questions, you are asked to make changes to the program itself to
give you experience in interpreting some of the compiler’s error messages. For each
question, make sure you undo the modifications before moving on to the next question.
(e) What happens if you change all occurrences of the word int to:
(i) short? (ii) long int? (iii) long?
(f) What is the principal (first) message you get if you remove any one left brace ({)?
(g) What is the principal message you get if you remove one right brace (} )?
(h) What is the principal message you get if you remove one semi-colon ( ; )?
(i) What happens if you remove both parentheses from the line cB(); on line 22?
(j) What effect is there on execution if you change every occurrence in the program of
the name num to inputNum?
(k) What effect is there on execution if you remove all spaces at the left side of the
window between the { and the} inside the method called main()?
(l) Why do some words such as while, do and return appear as a different colour than the
rest when viewed in your editor? What does that mean?
What to Hand in
Submit to Brightspace before the due date:
• A single document (.docx or .pdf) containing the answers to question 3a-l above. Make
sure to include the names and student numbers of all members of the group. Only one
person from the group will need to submit as Brightspace is expecting a group
submission, not an individual one.
Mark Allocation
OUT OF QUESTION
/3 3a with good explanation
/1 3b
/1 3c
/1 3d
/1 3e
/1 3h
/1 3k
/1 3l
Deductions
/-1 • The answers to some questions are missing
/10 TOTAL
2
LANGARA COLLEGE
COMPUTER SCIENCE 1150