Unformatted text preview:

CS100J Spring 2006 Assignment A5. Mozart's Musikalisches Würfelspiel. Due on the CMS at 11:59PM, Monday, 3 April The inspiration for this assigment comes from a similar assignment given by Kevin Wayne and Robert Sedgewick in Computer Science and Princeton. The purpose of the assignment is to show you the use of two-dimensional arrays in an interesting setting, which also get you familar with random-number generation. In 1787, Wolfgang Amadeus Mozart created a dice game ( ). In the game, you compose a two-part waltz by pasting together 32 of 272 pre-composed musical elements at random. The waltz consists of two parts: a minuet and a trio. Each is composed of 16 measures, which are generated at random according to a fixed set of rules, as described below.Mozart's Musikalisches WürfelspielThe minuet consists of 16 measures. There are 176 possible Minuet measures,named through . To determine which one to play, roll two fair dice, and use the following table.For example, if you roll an 11 for measure 3, then play measure .Minuet.M1.wav M176.wav 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16----------------------------------------------------------------------------------- 2 96 22 141 41 105 122 11 30 70 121 26 9 112 49 109 14 3 32 6 128 63 146 46 134 81 117 39 126 56 174 18 116 83 4 69 95 158 13 153 55 110 24 66 139 15 132 73 58 145 79 5 40 17 113 85 161 2 159 100 90 176 7 34 67 160 52 170 6 148 74 163 45 80 97 36 107 25 143 64 125 76 136 1 93 7 104 157 27 167 154 68 118 91 138 71 150 29 101 162 23 151 8 152 60 171 53 99 133 21 127 16 155 57 175 43 168 89 172 9 119 84 114 50 140 86 169 94 120 88 48 166 51 115 72 111 10 98 142 42 156 75 129 62 123 65 77 19 82 137 38 149 8 11 3 87 165 61 135 47 147 33 102 4 31 164 144 59 173 78 12 54 130 10 103 28 37 106 5 35 20 108 92 12 124 44 131165The trio consists of 16 measures. There are 96 possible Trio measures named through . To determine which one to play, roll one fair die, and use the following table.Trio. T1.wav T96.wav 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32------------------------------------------------------------------ 1 72 6 59 25 81 41 89 13 36 5 46 79 30 95 19 66 2 56 82 42 74 14 7 26 71 76 20 64 84 8 35 47 88 3 75 39 54 1 65 43 15 80 9 34 93 48 69 58 90 21 4 40 73 16 68 29 55 2 61 22 67 49 77 57 87 33 10 5 83 3 28 53 37 17 44 70 63 85 32 96 12 23 50 91 6 18 45 62 38 4 27 52 94 11 92 24 86 51 60 78 31 Here is a generated using this process and the . There are 11^16 * 6^16 different possible results, some of which are more likely than others. Since this is over 10^23 different possibilities, each time you play the game you are likely to compose a piece of music that has never been heard before! Mozart carefully constructed the measures to obey a rigid harmonic structure, so each waltz reflects Mozart's distinct style.Example. sample waltz accompanying musical score In this assignment, you will use a number of ideas for the first time: generation of random numbers, two-dimensional arrays, playing music stored in a .wav file, saving a double array that contains music in a file on your hard drive, and more. To help you learn all this and also to give you more advice on how to go about developing and testing programs, we lead you through this assignment in a series of steps. Please follow them carefully. When doing one step, don't go on to the next one until the current one is done and the method you wrote for it work! About this assignment. the following and place them all in a new folder for the assignment.File . Class contains methods for manipulating and playing music in wave (.wav) format.File . You will be writing class . We have provided you with a few components in it to help out.File (34MB) or (25MB). After downloading a file, unpack it —into a folder that contains all the .wav files for the measures used in Mozart's Musikalisches Würfelspiel. If you are on a PC, you probably have to use waves.zip; mac people can use the smaller .sitx file. Put folder in the folder with the two .java files.Step 1. DownloadStdAudio.java StdAudioMozart.java Mozartwaves.zip waves.sitx waveswaves. Your program will have to "roll a die" to produce a random number in the range 1..6. At the beginning of class , there is a declaration of a static variable . An object of class has methods for generating "random" numbers. The one you will use is function . Evaluation of a call yields an integer that satisfies . You should use function to write a method with the following specification in class :Step 2. Generating rolls of a dieMozart Random generatorgeneratornextInt generator.nextInt(t) i 0 ?… i < tnextInt Mozart/** = a roll of a die --an int in the range 1..6 */private static int throwDie()Class is in API package . Use the link in the course webpage to obtain the API spec for and spend some time becoming familiar with it. Random java.util RandomFunction seems extremely simple! Nevertheless, it has to be tested to make sure that it will produce only integers in the range 1..6 and can produce all integers in that range. Test it! One way is to write a method that callsthe 50 times, each time printing the result in the interactions pane. Then you can look at the values it produced.throwDiethrowDie Later, you will be writing a function that produces a array of file names corresponding to measures to be played. In order to see that the method works, you have to see thearray of . For that purpose, write and test the following function.Step 3. A method for printing a String array. StringStrings/** = a representation of array s --the list of Strings in the array, with each pair separated by ", " and the list delimited by "[" and "]". Example: "[first, second, what]" */public static String toString(String[]


View Full Document

CORNELL CS 100 - Study Notes

Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?