CSE 131 Module 4: Input & Output

Extensions

Extension 1: Create an Instrument (6 points):

Authors
We have seen how sound can be represented as a summation of sine waves. In this extension, you will process a description of an instrument, which specifies the relative intensities of that instruments overtones. You will modify a copy of PlayThatTune so that the sound emitted for each note has the profile of the specified instrument.

Warm Up

Overview

Procedure

  1. First prompt the user for how many frequency factors the user wishes to specify. In the above example, 3 such frequencies were used.
  2. For each frequency factor, prompt the user for its
    The information about the frequency factors must be saved (in arrays) for future use.
  3. The code in PlayThatTune, copied with attribution from PlayThatTune, reads in a file and computes a value in a variable called hz that is the fundamental frequency of the tune being played.
    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.

  4. Your task is to modify the assignment to the sample a[i] in the provided code:
    The sine wave sampled and assigned there is for:

    In place of that value, you must compute the sum of sine wave samples, one for each frequency factor, as follows:

  5. Test your program on the A.txt file first, which is a single note. Then try Ascale.txt and some other songs.
When you done with this extension, you must be cleared by the TA to receive credit.

This demo box is for extension 4.1
Last name WUSTL Key Propagate?
(or your numeric ID) Do not propagate
e.g. Smith j.smith
1 Copy from 1 to all others
2 Copy from 2 to all others

TA: Password:

End of extension 1


Extension 2: Draw a Sound Wave (10 points):

Authors

Warm Up

To understand this extension, you should first be familiar with the extension in which an instrument's sound is produced as the sum of sine waves.

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!

Procedure

When you done with this extension, you must be cleared by the TA to receive credit.

This demo box is for extension 4.2
Last name WUSTL Key Propagate?
(or your numeric ID) Do not propagate
e.g. Smith j.smith
1 Copy from 1 to all others
2 Copy from 2 to all others

TA: Password:

End of extension 2


Extension 3: Loud or Graphics-ful Bouncing Balls (2 points):

Authors

Extension points available for Lab 4

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.

This demo box is for extension 4.3
Last name WUSTL Key Propagate?
(or your numeric ID) Do not propagate
e.g. Smith j.smith
1 Copy from 1 to all others
2 Copy from 2 to all others

TA: Password:

End of extension 3


Extension 4: Magic 8 Ball (7 points):

Authors
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.

This demo box is for extension 4.4
Last name WUSTL Key Propagate?
(or your numeric ID) Do not propagate
e.g. Smith j.smith
1 Copy from 1 to all others
2 Copy from 2 to all others

TA: Password:

End of extension 4


Extension 5: Roving Eyes (10 points):

Authors
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.

The idea

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.

Part 0: Initialize your application

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.

Part 1: Detecting mouse clicks

Most programs that interact with the mouse use a listener model that takes action when the mouse is moved, pressed, released, or clicked (a press and release action).

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:

Mouse press
We think of this as a single push-down action on a mouse or trackpad. This action usually initiates some activity in 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.
Mouse release
If a mouse has been pressed, then it can be released. Some applications distinguish between the press and release, so that the mouse can move between those actions. This is sometimes called dragging the mouse.
Mouse click
While this is a compound action, consisting of a mouse press followed by a mouse release, it is usually treated as an atomic action that takes place at exactly one coordinate. The release also happens within some reasonable timeframe of the press, if the press and release are to be construed as a click.
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.

double mouseX()
returns the x-coordinate of the mouse, expressed in terms of the coordinates of the StdDraw canvas.
double mouseY()
returns the y-coordinate of the mouse, expressed in terms of the coordinates of the StdDraw canvas.
boolean mousePressed()
A better name for this would be boolean isMouseDown(), because this method does not detect a mouse press in the standard view of mouse actions. Instead it simply reports whether the mouse button is currently pressed or not.

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.

Part 2: Following the mouse movement

A pupil within an eyeball tracks objects using the geometry of similar triangles. The following diagram and discussion may be useful.

Putting it all together

Your code is like the bouncing ball code, in that it enacts a sequence of frames. Each frame consists of checking whether and where a new eyeball should be deposited. Moreover, all existing eyeballs must be updated so that they appear to be tracking the mouse as it moves through the window.

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.

This demo box is for extension 4.5
Last name WUSTL Key Propagate?
(or your numeric ID) Do not propagate
e.g. Smith j.smith
1 Copy from 1 to all others
2 Copy from 2 to all others

TA: Password:

End of extension 5


Extension 6: Roving Eyes; Slow Motion Edition (5 points):

Authors
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.
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.

This demo box is for extension 4.6
Last name WUSTL Key Propagate?
(or your numeric ID) Do not propagate
e.g. Smith j.smith
1 Copy from 1 to all others
2 Copy from 2 to all others

TA: Password:

End of extension 6


Extension 7: Web Scraper (3 points):

Authors

Intro

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:

URLs and web sites
Simple use of jsoup
In this assignment, you will process the text yourself after getting the document's text using jsoup. You could use methods in jsoup to isolate what you need, but you can explore that on your own.

Procedure

Demo

When you done with this extension, you must be cleared by the TA to receive credit.

This demo box is for extension 4.7
Last name WUSTL Key Propagate?
(or your numeric ID) Do not propagate
e.g. Smith j.smith
1 Copy from 1 to all others
2 Copy from 2 to all others

TA: Password:

End of extension 7


Extension 8: Stock Scraper (0 points):

Authors
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.

Overview

Stocks represent equity ownership in a company and can either be rapidly traded for the purpose of profiting from price fluctuations or can be held in the long-term for the purpose of developing a substantial stake in a corporation which grants voting rights and a general 'say' in the day-to-day operations of the company, among other things. As such, it can be useful to know the current stock price in real-time in order to track changes and monitor an investment.

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.

Procedure

Example

Input: INTC

Stock 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.

Demo