In the example below, let's assume that f is 440 Hz (cycles per second), which is concert A. On a piano, this is the A above middle C:
- a factor of 1 results in the same frequency as f, because 1*f==f.
- a factor of 2 yields a frequency an octave higher than f.
For this example, we obtain 880 Hz, which is the A above high C on a piano:
- a factor of 4 yields a frequency two octaves higher than f.
Here we obtain 1760 Hz, an octave above the A above high C:
- a factor of 3 is between one and two octaves higher, and it turns out to be one octave plus a just (or, pure) fifth above the pitch corresponding to f. Here we obtain the frequency 1320 Hz, which sounds like the E above high C.
The sound is slightly different than on a piano, where the pitches are not perfect but are instead evenly spaced apart from each other. The corresponding note on the piano has a frequency of 1318.51 Hz, slightly flatter than what we get by our frequency factor. - a factor of 0.75 (ratio of 3:4) yields a note that sounds like an E, but dividing by 4 lowers its pitch by two octaves. With f at concert A, a frequency factor of 3:4 yields a frequency of 330, whichsounds like the E above middle C:
Again, the pitch on a piano is slightly different; in this case it is slightly flatter at 329.63.
The first row is the fundamental frequency. The second is an octave higher, and is 3/4 as strong as the fundamental frequency. The third row specifies a pitch that is a fifth above the fundamental freqnecy, and quieter still at half the strength of the fundamental frequency.
Frequency Factor Relative Numerator Denominator Strength 1 1 1 2 1 0.75 3 2 0.50
The waveform that results from such an instrument specification is shown below in red, with the three frequency factors shown in black:
- The red solid waveform is literally the sum of the black dotted waveforms. The sound you produce is sampled from the red waveform, and that is the subject of this extension.
- The plot shown above is not the subject of this extension, but is shown to help explain how complex sounds are built from simple ones, as follows:
- The black waveform with the largest amplitude (the tallest black waveform) is the fundamental frequency at relative strength 1. The sample shown is for 1/440 of a second of a 440 Hz concert-A. This is sufficient ot show one full cycle of the fundamental frequency.
- The black waveform with the next largest amplitude has relative strength 0.75. It is an octave higher, so it oscillates twice in the timespan of the fundamental pitch's waveform.
- The black waveform of smallest amplitude (at half the strength of the fundamental frequency) is the 3:2 frequency factor, which sounds like a fifth above the fundamental frequency. As expected, it exhibits 1.5 cycles in the timespan of the fundamental pitch's waveform.
- The sound of the red waveform, which is what you will produce below, is similar to an oboe or a clarinet (in the opinion of my son).
The information about the frequency factors must be saved (in arrays) for future use.
The hz value is computed from concert A (440 Hz), taking the specified number of equally spaced chromatic steps above (or below) concert A.The relevant details, explained in the lecture slides for this module, are not necessary to complete this extension, but please ask if you would like clarification.

In place of that value, you must compute the sum of sine wave samples, one for each frequency factor, as follows:
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.1
You will modify your program further in this extension to produce the sine-wave plots that depict how sine-wave addition occurs.
The details of this assignment are not completely specified so that you must think through what is needed to produce meaningful plots. Ask for help as needed!

Think about how many samples you need to capture to show one complete cycle at 440 Hz.One way to reason about this is to use the units of the various computations and multiply or divide them to obtain the property you seek.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.2
Trevor Larsen and Tyler Spinks submitted this video for your amusement, as a demo of this extension. It is based on the John Cena Prank Call video.
If you have added sound or pictures to your solution for Lab 4, demo those to a TA and receive points for this extension.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.3
A video demonstrating my solution can be found here.
The Magic Eight Ball is an autoresolution device. A question of boolean type is posed, the Magic Eight Ball is turned over, and it then displays its advice in a murky window. It has resurfaced in other guises over the ages, most recently perhaps as The Magic Conch Shell in the Club SpongeBob episode of SpongeBob SquarePants.
To receive credit for this extension, your implementation of the Magic 8 Ball must:
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.4
A video demonstrating my solution can be found here.
This extension has been brought back from the 131 vaults, having originally been conceived by Ken Goldman, formerly a professor in our department and currently at Google. In its new form, it has been rewritten to comform to Sedgewick's API. Also, it does not make use of objects, so it can be offered as an extension at this point in the course.Although the solution can be quite short (mine weighed in at approximately 50 lines), there are some tricky aspects to this work, and it may be an extension that you work on over several weeks.
You will have to interact with the mouse, perhaps for the first time, both in terms of its location and determining whether the mouse has been pressed and released. It will take patience to get this to work, but most students like the end result.
|
|
|
|
| This is the initial image you should draw. The picture can be found as images/ken.jpg in your workspace. | Here, I have clicked over the image to deposit my first eyeball. The mouse (not shown) is to the right, so the eyeball is looking that way. | Then I clicked a second time to deposit another eyeball, this time
over the right eye shown in the image.
Both eyeballs are looking at my mouse, which is at the lower right (not shown). |
Each time I click the mouse, another eyeball is deposited, and all eyeballs continue looking at my mouse, wherever it happens to be. |
This code is included in your repository. Open the extensions folder in which you will find the eyeballs package. Open and run the Eyeballs class.
Unfortunately, in Sedgewick's API, we can only determine the current status of a mouse button as up or down. We must then use logic and iteration to discover whether a mouse has been pressed, released, or clicked. This low-level API for the mouse leads to some mixed feelings about how you are learning to interact with the mouse:
Following is a description of mouse actions as they are typically used in most applications:
From an application's point of view, this event happens just once when the mouse is pushed down. Generation of another mouse press action would require the mouse to be released, and then pressed again.
The above mouse actions are the logical ones that we wish to implement. Actually, it suffices for this extension to determine only a mouse release, but you are welcome to think about how to discover the other actions.
The Sedgwick API offers only the following interface, which we must use in our application to simulate the above mouse actions.
Your task is to simulate a mouse-click action using the above API. This will inevitably involve polling the mouse as to whether the button is down or up. Consider the following code:
while (!StdDraw.mousePressed()) {
// do nothing,
// we are waiting for the mouse button to go down
//
// The line below is important, as described below
//
StdDraw.show(50);
}
Make sure your eyeballs are depositing properly as you mouse-click before you move on to implement more features.
A pupil within an eyeball tracks objects using the geometry of similar triangles. The following diagram and discussion may be useful.
Give yourself time for this extension, and develop and test the aspects in the order described above.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.5
To do this extension, you must first complete the one above and successfully demo it. Then you can earn the points for this extension by causing the eyes to move slowly from where they were looking to where they should be looking.
- We suggest that you wait until you have completed module 5 to do this extension, as the information in module 5 will help.
- A video demonstrating a solution can be found here.
You are not allowed to do this by slowing the simulation down. Instead, you must smoothly vary where the eyes should look in the normal speed of the simulation.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.6
Web scrapers are programs that search websites and scrape off useful data. You will write a web scraper in this assignment that looks for weather information in a zip code of interest. There are two ways to go about this:
Reverse engineering skills are useful skills and can serve you well.
Browsers vary in how they allow you to see the page source. If you are on the web page of interest, try control- (right-) clicking and one option you should see should resemble View Page Source.If you are lost, try Googling for how to view page source in your browser.
- What makes this difficult is that the author of the web page doesn't know you want to find this information.
- You have to look at the web page yourself to find distinguishing features of the page near where you want to extract information.
- Worse still, the author of that web page is not obligated to keep the information you see in future versions of that web page. Scraping is a dodgy effort at best, and you may have to revise your code in response to changes made by the author of the pages you scrape.
- int indexof(String str)
- Finds the location of the specified str in t.
- String substring(int beginIndex)
- Returns a new String that is copied from t, starting at the supplied beginIndex.
- String substring(int beginIndex, endIndex)
- Returns a new String that is the substring of t, starting at the supplied beginIndex, up to but not including endIndex.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.7
It is highly recommended that you complete the easyStrings assignment before attempting this assignment.Additionally, this assignment builds off of the Web Scraper assignment and it is recommended that you complete that assignment prior to attempting this one. If you decide to work on this assignment without having completed the former, it is, however, necessary that you watch the two videos provided in the Web Scraper assignment in order to fully understand this assignment.
In this assignment, you will access the Yahoo! Finance website, store the HTML code of the website in a String, and extract the current stock price of a company (along with some other useful information). You will use the API provided through Jsoup to download and store the HTML code of the website, which you learned how to do through the aforementioned Web Scraper assignment videos. Once you've stored the HTML code of the website in a String, you will then analyze the code to find the relevant information and come up with a unique identifying String which will allow you to extract the stock information.
Specifically, you are looking for three different pieces of information that you will extract and print.
- The full name of the company in question.
- The current price of the stock.
- The % daily change in stock price. (This is provided as its own element in the HTML code and therefore does not require any computation on your part)
- int indexof(String str)
- Returns the location of the specified str in t.
- char charAt(int i)
- Returns the character at index i in t.
- boolean Character.isDigit(char c)
- Returns true if c is a digit and false otherwise.
- String Character.toString(char c)
- Returns the String representation of a character.
- int Integer.parseInt(String s)
- Returns the int representation of a String.
Input: INTCStock information for Intel Corporation
The stock most recently opened at $31.87
The current stock price is $31.88 which is a -0.38% change today.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.8
This extension should be placed before all other web scraping extensions
For this assignment, you are given two different arithmetic expressions as Strings. Your task is to extract the two integer values and the arithmetic operator from each String and save them as variables of their respective type. You will then compute and print the value of the expression.
Given: String s = "2 + 3";You must first extract 2 and 3 to int variables and + to a char or String variable. Then you will compute and print the expression 2+3=5
As previously mentioned, the purpose of this assignment is to prepare you for dynamic web scraping tasks. As such, it is expected that you implement this assignment dynamically. In other words, the only assumption you should have about the String you are analyzing is that it will be in the format (Positive Integer)(Arithmetic Operator)(Positive Integer). This implies your implementation should be able to run effectively on an expression containing positive integers of any length. It should also be able to effectively extract any arithmetic operator (+, -, *, /) and print the proper answer.It is important to note that there are many acceptable ways to implement this assignment. It is up to your discretion which way you choose to implement the procedure as long as it abides by the requirements described above.
- int indexof(String str)
- Returns the location of the specified str in t.
- char charAt(int i)
- Returns the character at index i in t.
- boolean Character.isDigit(char c)
- Returns true if c is a digit and false otherwise.
- String Character.toString(char c)
- Returns the String representation of a character.
- int Integer.parseInt(String s)
- Returns the int representation of a String.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.9
This assignment is a continuation of the Gambler's Ruin assignment from Module 2. You must first complete and demo that assignment before you can demo this assignment.
Think of a way to store these values, as you will be using them throughout your program.
You must import java.io.FileWriter to use this class.
Remember that each line in your CSV file is its own row. How can you use the append method and your array to write multiple rows to the CSV file?
| startAmount | stopAmount | winChance | rounds | results |
| 12 | 18 | 0.1 | 14 | LOSE |
| 12 | 18 | 0.1 | 14 | LOSE |
| 12 | 18 | 0.1 | 12 | LOSE |
| 12 | 18 | 0.4 | 18 | LOSE |
| 12 | 18 | 0.4 | 46 | LOSE |
| 12 | 18 | 0.4 | 18 | LOSE |
| 12 | 18 | 0.7 | 14 | WIN |
| 12 | 18 | 0.7 | 44 | WIN |
| 12 | 18 | 0.7 | 8 | WIN |
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.10
AJAX, or Asyncronous Javascript and XML, is a web technology that allows a website to request data from a server in the background (asyncronously) in order to provide a more rich and dynamic experience for the end user. Since all communication with the server happens behind the scenes, the webpage that the user sees and interacts with becomes faster and doesn't need to refresh nearly as often.
By retrieving data and updating the page without refreshing, however, our ability to scrape the page simply by modifying the URL is forfited. As a result, we are forced to get a bit more creative in our scraping approach. It turns out that it is, in fact, possible to scrape these pages and just requires some research and digging on our part.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.90
For this extension you will re-use your nutrition code from Lab 1, and potentially the C++ code you wrote from the similar extension. The difference is that this time instead of writing the information to terminal, you will use a file to write out the nutrition info and the analysis. You will then demonstrate your ability to read back in that file.
By completing this work, you demonstrate that you can:
- Utilize the input/output features of C++
- Incorporate new headers into existing work
- Produce meaningful output based on your computations
Procedure
You will need to prompt the user for inputs just as before and calculate the same boolean values and caloric values
You will need to initailize a ofstream which stands for output file stream
You will also need to initialize a ifstream which stands for input file stream
Arrange for your program to produce output such that:
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for extension 4.100