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/fall16/lessons and open this lesson
Questions
- Reading?
- Interactivities?
- Homework?
Activity - Nested Loops
Record your participation in Piazza clicker question Lesson14 Q1
Write a pair of nested loops to print the following pattern. We will do it together
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
Activity - Nested loops
Record your participation in Piazza clicker question Lesson14 Q2
Write nested loops that make the following pattern of brackets: (Note: there are no spaces)
[][][][]
[][][][]
[][][][]
- Got it
- Got it but it was hard
- Couldn't do it in the time allowed
- Didn't know where to start
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. Unless otherwise stated, the range is inclusive of the first number and exclusive of the last number
- between 0 and 50 (exclusive)
- between 1 and 25 (inclusive)
- between 10 and 30 (inclusive)
- between -20 and 20 (inclusive)
Program with a bug
Record your participation in Piazza clicker question Lesson14 Q4
- Getting the application
- Look at the MagicPotion class
- What the MagicPotion class is suppose to do
- A MagicPotion is a cylinder filled with a magic potion that has a set cost per cubic centimeter
- It has a constructor,
- a method to set a new height,
- a method to get volume,
- a method to get the cost.
- Run it
- Third "Expected" is incorrect.
Activity - Using the Bluej debugger - MagicPotion
Record your participation in Piazza clicker question Lesson14 Q5
- Open MagicPotionTester 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 getCost
- Will the correct value be returned?
- Step back to the tester
- Step: what is printed?
- Step: what is the expected value
- Step into setHeight
- Notice the local variable
- Step: is the height set correctly?
- Step: back to tester
- Step into getCost
- 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 youuse 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