CSE 131 Module 4: Input & Output

Studio


If necessary, review studio procedures before starting.

Warmup


Overview

In honor of the upcoming UN Day, you will select (or design) a flag of your choice and create that flag using the drawing methods available in Sedgewick's library.
Here is the one I created:

Resources

You may find the following resources helpful for this studio:
Warning The book is missing some of the functionality that is in the Sedgewick library. For example, the book is missing the method that draws a filled rectangle, and that can be useful for drawing a flag.

See the link above for the full range of possibilities.

Procedure

Design your flag
  1. Visit the Flags of all Countries web site, and decide on a flag that your studio group would like to create for this studio.
    Pick a flag that has at least 3 shapes on it. If you need to approximate something by a standard shape, say a maple leaf by a circle, that's fine.

    Also, if you want to design your own flag, that's fine. Make sure it has at least 3 shapes in it. Try to come up with a cool name for your flag's country.

  2. Open the studio4 package int he studios source folder, and open the Flag class.
    • That class is currently empty except for the main.
    • Insert code that creates the flag of your choice.
      Notes:
      • Most of the drawing methods want the center of the object to be drawn, along with a radius, or a half-width, or a half-height. Be aware of this!
      • If you want colors, they are already in the Sedgewick libraries. If you start to type something like:
        sedgewick.
        
        then eclipse will fill in possiblities after the . which will include the colors at the top of that list.
    • Frame your flag by surrounding it by a black rectangle of substantial thickness, (unfilled).
    • When done, allow your studio neighbors and TAs to admire its beauty.
Display the name of your country
  1. In the center of your flag, using a color that allows the text to stand out, write the name of your country on top of your flag.
  2. In a (literally) moving display of patriotism, arrange for your program to print the name of your country repeatedly, from the upper-left-hand corner to the lower-right-hand corner.
    For more drama, pause for a bit between each printing of the country's name, to allow for cheering from the crowd. Take a look at the show(int t) method to achieve the pause.
Compose an anthem for your flag
  1. Find the PlayThatTune program in the book source folder, in the book.ch1 package.
  2. Run the program and make sure you can hear some sound when you play a given piece.
    The music inputs come from the music folder in your workspace. The program lets you choose any of the files in that directory, or you can navigate elsewhere if you wish.
  3. Based on what you see in the Ascale.txt file, design a piece that is your own anthem by specifying the pitches and durations.
    You can do this by modifying an existing file in the music folder (for example, there is already a National_Anthem.txt file, so you can just modify that), or you can create a new text file in that same folder and place your composition there.

    If you are really unclear how to do this, no problem, you can just use one of the existing compositions.

    Or, you could generate tones and durations randomly. Pick values that seem similar to what you see in the music files.

  4. Try PlayThatTune and select your composition for playing.
  5. Once you like it, copy and paste the appropriate code from PlayThatTune into your Flag program so the anthem plays after your flag and text are drawn.
    • The code you want is everything inside the main method; get help if necessary.
    • When you run your code, you will have to select the anthem by hand.
    • If you want the file to open without the user having to choose it, then replace the line
      ArgsProcessor.useStdInput("music");
      
      with
      System.setIn(new FileInputStream("music/National_Anthem.txt"));
      
      Eclipse will provide guidance about importing the right classes so this will work.
  6. See if you can figure out how to get your anthem to play repeatedly.
    This may not seem easy, but it builds on what you know about arrays and iteration.

Submitting your work (read carefully)



Last modified 11:27:54 CST 30 November 2012
When you done with this studio, you must be cleared by the TA to receive credit.

Studio repo name: studio4- (from your sticker)

People on your team:

Last name 6-digit ID
1
2
3
4
5
6

TA: Password: