Prep 3: Module 3
- Introduction to Arrays
- Exercise: Make a copy of an array
- A perfect shuffle (or is it?)
- Roundtable: Perfect Shuffle
- Roundtable: What does it mean to be random?
- Permuting an array
- Exercise: Permuting an array
- Two-dimensional arrays
- Exercise: Multiplication Table
- Roundtable: The birthday problem
- Conclusion
Introduction to Arrays
| Video | Description |
|---|---|
| Module Overview | An overview of the concepts that will be covered in this module |
| Module Introduction | An introduction to arrays and why they are useful |
| Examples of Arrays | This video shows a few examples of how arrays can be used |
| Array Syntax | How do we create arrays? How do we use them? |
Exercise: Make a copy of an array
Part 1: Introduction
Introduction: Make a copy of an array
Part 2: The exercise
There are two parts to this exercise:
- First you will make a copy of an array.
- Then you will change your code so that as you copy, you create the Pig Latin version of each string from the original array.
- Find and open the CopyArraysAndPigLatin Java program in the exercises3 package of the exercises source folder.
- Write code to make a copy of the provided names array.
We do this so that we can
make changes to the copy without affecting the original array.
If we call the copy array copy, then the steps you take
are as follows:
- Allocate the copy array with enough space to hold each of the elements of name.
Do not use constants here: pretend that the names array could be of any length. * Iterate over the names array to assign each element of copy from names.
- Check your results by iterating over copy and printing each element.
- Now go back and cause each element of the copy array to have the Pig Latin version of each string in the original names array.
Part 3: The solution
Solution: Make a copy of an array
A perfect shuffle (or is it?)
Roundtable: Perfect Shuffle
| Video |
|---|
| Part 1 |
| Part 2 |
Roundtable: What does it mean to be random?
What does it mean to be random?
Permuting an array
Exercise: Permuting an array
Part 1: Introduction
Introduction: Permuting an array
Part 2: The Exercise
- Find and open the Shuffle Java program in the exercises3 package of the exercises source folder.
- It declares an array of strings called original that contains the strings A through H, in alphabetical order.
- The goal of this exercise is to shuffle this array, or a copy of it as you prefer, so at to obtain a randomized order of the strings.
- This is tricky, so try your best but don’t feel bad if you need to see the solution before you have it working completely.
You can watch just enough of the solution video to get unstuck and then try moving forward on your own.
Part 3: The Solution
Two-dimensional arrays
Exercise: Multiplication Table
Part 1: Introduction
Introduction: Multiplication Table
Part 2: The exercise
- Long before computers existed as electronic machines, the word computor was a name for a human whose job consisted of computing and tabulating mathematical results.
- In this exercise, you produce a table of products.
###Instructions
- Find and open the TimesTable Java program in the exercises3 package of the exercises source folder.
- Complete the class so it prints a table of products, as shown on the introductory video.
Your columns should line up nicely, assuming that all products take at most 2 digits. In other words, it should look nice when given an input value of 9. For greater values, your columns need not line up but the data should be correct.
Part 3: The Solution
Solution: Multiplication Table
Roundtable: The birthday problem
| Video |
|---|
| Part 1 |
| Part 2 |
| Part 3 |
| Part 4 |
| Part 5 |
| Part 6 |