Lesson 14 – Nested loops

When you come in
- Connect to the Internet
- Log in to Piazza
- Start Bluej
- Navigate to laughton.com/obrien/sjsu/cs46a/CRT_lessons/ and open this lesson
Activity - Nested Loops
Record your participation in Piazza clicker question Lesson14 Q1
Write a pair of nested loops to print the following pattern. Don't just print "[][][][][][]" 3 times.We will do it together
[][][][][]
[][][][][]
[][][][][]
Activity - Nested loops
Record your participation in Piazza clicker question Lesson14 Q2
Write nested loops that make the following pattern of symbols: (Note: there are no spaces)
We will do this together also
#
##
###
####
#####
######
Concept - Random numbers
- Construct an object of the Random class
- Most useful method is nextInt(int n)
- To get a random number between 0 and 10 (exclusive)
- To get a random number between 1 and 10 (inclusive)
- To get a number between 90 and 100 (inclusive)
- To get a number between 90 and 100 (exclusive)
Activity - Random numbers
Record your participation in Piazza clicker question Lesson14 Q3
Write the segment of code to generate a random integer.
- between 0 and 50 (exclusive)
- between 0 and 20 (exclusive)
- between 1 and 50 (inclusive)
- between 1 and 25 (inclusive)
- between 10 and 30 (inclusive)
Program with a bug
Record your participation in Piazza clicker question Lesson14 Q4
- Getting the application
- Download debug Cylinder.zip
- Unzip
- Start the application (by double clicking the bluej.package icon
- Look at the Cylinder class
- What the Cylinder class is suppose to do
- Models a cylinder
- It has a constructor,
- a method to set a new height,
- a method to get volume,
- Run it
- Second "Expected" is incorrect.
Activity - Using the Bluej debugger - Cylinder
Record your participation in Piazza clicker question Lesson14 Q5
- Open CylinderTester class
- Set a breakpoint at line 9 (do you know how to turn on line numbers?)
- Run
- Step into the constructor
- Notice the values of the local variables
- Step 3 times and up to the closing brace }
- Are the instance variables set correctly?
- Step again - (back to the constructor in the tester)
- Step again
- Step into getVolume
- Step: look at the local variable areaOfCircle
- Step: does volume look correct?
- Step: back to the tester
- Step one more time and look at the output
- Step: look at expected
- Step into setHeight
- Notice the parameter
- Step: is the height set correctly?
- Step: back to tester
- Step into getVolume
- What value should be calculated?
- What value is calculated?
- Step: back to tester
- Continue to finish program
Activity - Using the Bluej debugger - StringIndexOutOfBounds
Record your participation in Piazza clicker question Lesson14 Q6
This program throws an exception.
Can you use the debugger to find out why?
- Figured it out
- Figured it but it was hard
- Couldn't do it in the time allowed
- Didn't know where to start
Lesson 6.2 on Udacity starting at unit 29 has a good set of videos on using the debugger where you can get more practice