JF 2 14 Practice
JF 2 14 Practice
com
Java Fundamentals
2-14: Java Methods and Classes
Practice Activities
Lesson Objectives:
• Describe a method, class, and instance
• Describe a scenario where an IF control structure would be used
• Describe a scenario where a WHILE control structure would be used
• Recognize the syntax for a method, class, function, and procedure
• Describe input and output
Vocabulary:
Identify the vocabulary word for each definition below.
Statements that allow you to select and execute specific blocks of code while skipping
other sections.
An object of a class.
Control structure that allows you to execute specific sections of the code a number of
times.
e. Change the code so that before the child exercises, you declare a variable of type Integer called numSets.
Set the default value to 3. Save your animation.
f. Use this value to control how many sets of exercises the child does.
g. Have the child wave and say goodbye at the end of the animation.
h. Modify the numSets variable so that it asks the user how many sets the child should do. (Hint: use the
getIntegerfromUser function.)
i. Using a while loop have the child say the number of sets remaining. When there is one set remaining, the
child should say “Last set.” (Hint: use an IF control statement.)
j. Save your animation.
2. Build on the previous animation from practice activity #1 above and add two other children to the animation with dif-
ferent variables (numset, numset2, numset3) to control their number of sets. Save your animation.
3. If you look at the code for the exercise program you can see that there is a lot of duplication in the myFirstMethod.
a. Create a procedure called exercise and move the code block that has the while loop and the “I’m done
exercising” statement from myFirstMethod to the new exercise procedure. Do this through the clipboard.
b. Create a parameter called numSets of type wholenumber
c. Add a local variable to the exercise procedure named sets of type wholenumber set its initial value equal to
numsets.
d. Change the instances of numsets in the code to sets
e. Replace the line that says numsets = numsets -1 to use the sets variable instead.
f. Save your animation.
5. In Alice 3, create an animation that uses both the IF and WHILE control structures to control an object's movement.
Construct Syntax
IF ELSE syntax
WHILE syntax
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.