Prep 5: Module 5

Module Overview

Module Overview

Module Introduction

Module Introduction

Exercise: Cooking Abstractions

Part 1: Introduction

Cooking Abstractions: Introduction

Part 2: The Exercise

  • Find and open the Recipe Java program in the exercises5 package of the exercises source 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

Method Syntax

Encapsulation via Scopes

Encapsulation via Scopes

Exercise: Method Exercises

Part 1: Introduction

Method Exercises: Introduction

Part 2: The exercise

  • Find and open the StringMethods Java program in the exercises5 package of the exercises source folder.
  • Write the methods described below into the program.
  • Call those methods from the main method 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 String and returns that string concatenated with itself. This one is completed for you.

  • A method that takes in a String and an int n, 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 String into an array containing the parts split by the specified regular expression.

Here, assume the regular expression is simply " ", so that the input String is split into words.

  • Write a method join(String[] array, String joiner) that is the inverse of split: it returns a single String with a copy of the joiner string 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 your join method 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

Method Exercises: Solution

Execution of Methods

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

Conclusion

Conclusion