Prep 5: Module 5
- Module Overview
- Module Introduction
- Exercise: Cooking Abstractions
- Method Syntax
- Encapsulation via Scopes
- Exercise: Method Exercises
- Execution of Methods
- Roundtable: Method Execution using the Debugger
- Roundtable: More Tracing using the Debugger
- Conclusion
Module Overview
Module Introduction
Exercise: Cooking Abstractions
Part 1: Introduction
Cooking Abstractions: Introduction
Part 2: The Exercise
-
Find and open the
RecipeJava program in theexercises5package of theexercisessource folder. -
For the work below, enter your work into that file.
In the introductory video for this exercise, you heard the following recipe excerpt:
-
Heat 200 cc water to 100 degrees
-
Stir in 5 grams of yeast
-
Melt butter and stur in the vanilla with the butter
-
After 5 minutes, combine yeast with butter, sugar, and flour
-
Place the mixture in a 110 degree oven to rise for 45 minutes
-
Divide the mixture into 10 equally sized portions and cook for 45 minutes at 350 degrees
Define abstractions present in the above recipe. Rephrase the recipe in terms of your abstractions.
Part 3: Solution
Cooking Abstractions: Solution
Method Syntax
Encapsulation via Scopes
Exercise: Method Exercises
Part 1: Introduction
Method Exercises: Introduction
Part 2: The exercise
- Find and open the
StringMethodsJava program in theexercises5package of theexercisessource folder. - Write the methods described below into the program.
- Call those methods from the
mainmethod and print out the results to check that your work is correct. - The first method is completed for you already.
The methods you should write:
-
A method that takes in a
Stringand returns that string concatenated with itself. This one is completed for you. -
A method that takes in a
Stringand anintn, and returns n copies of the string concatenated together -
Now go back and rewrite your first method by having it call the second one.
-
Take a look at Java’s split method, that splits a
Stringinto an array containing the parts split by the specified regular expression.
Here, assume the regular expression is simply " ", so that the input
Stringis split into words.
-
Write a method
join(String[] array, String joiner)that is the inverse of split: it returns a singleStringwith a copy of thejoinerstring between each part. -
Rewrite your second method in terms of this last one. To do this, create an array that has n copies of a given
String, and then use yourjoinmethod to concatenate them.
Think about the string you want to appear between the copies, so that it appears the strings were concontenated together as before.
Part 3: Solution
Execution of Methods
Roundtable: Method Execution using the Debugger
| Video |
|---|
| Part 1 |
| Part 2 |
| Part 3 |
| Part 4 |
Roundtable: More Tracing using the Debugger
| Video |
|---|
| Part 1 |
| Part 2 |