<< Chapter < Page Chapter >> Page >

.....

Listing 8 . The class named MusicComposer08.
/*File MusicComposer08.java Copyright 2014, R.G.BaldwinRevised 08/24/14 This program demonstrates late binding and runtime polymorphism using an arrayof the abstract type AudioSignalGenerator02 populated with references to objects of the following classes:AudioGraphSinusoidal AudioGraphSquareWaveFMSweep SquareWaveStereoPingpong ToneMonoTonesStereoWhiteNoise Each of the classes listed above extends the abstract class namedAudioSignalGenerator02 and overrides the abstract method named getMelody. After the array is populated, a random number generator is used to get arandom index into the array. The getMelody method is called on the reference pointed to by the random index. This causes the sound created by that audioobject to be played or filed. This is an example of late binding because the compiler cannot possibly know the value of the random index when the programis compiled. The sound can be played immediately or can be saved in an audio file oftype AU for playback later. You should be able to play the audio file with any standard media player that can handle the AU file type.The program also requires access to the following classes: AudioFormatParameters01AudioPlayOrFile01 AudioSignalGenerator02Tested using JDK 1.8 under Win 7. ******************************************************************************/import java.util.Random; public class MusicComposer08{//Instantiate an object containing audio format parameters with predefined // values. They may be modified by the signal generator at runtime. Values// allowed by Java SDK 1.4.1 are shown in comments in the class definition. AudioFormatParameters01 audioParams = new AudioFormatParameters01();//A buffer to hold the audio data that will be played or filed.byte[] melody;//A place to store the incoming args array.String[] args;//-------------------------------------------------------------------------// //Command-line parameter (only one parameter is needed)//If "play", the sound will be played immediately. Otherwise, the string will // be used as a filename for an audio file of type AU. In the latter case,// it must be a string that would be valid as a file name for the operating // system in use.public static void main(String[] args){//Instantiate a new object of this class. new MusicComposer08(args);}//end main //-------------------------------------------------------------------------//public MusicComposer08(String[]args){//constructor //Save the args array.this.args = args;//Create default args data if no args data is provided on the command line. if(args.length == 0){this.args = new String[1];this.args[0] = "play";//Play the melody immediately}//end if//Create an array capable of holding references to eight audio objects // instantiated from subclasses of the AudioSignalGenerator02 class.AudioSignalGenerator02[] audioObjects = new AudioSignalGenerator02[8];//Populate the array elements with references to eight different // audio objects.audioObjects[0] = new AudioGraphSinusoidal(audioParams,this.args,melody);audioObjects[1] = new AudioGraphSquareWave(audioParams,this.args,melody);audioObjects[2] = new FMSweep(audioParams,this.args,melody);audioObjects[3] = new SquareWave(audioParams,this.args,melody);audioObjects[4] = new StereoPingpong(audioParams,this.args,melody);audioObjects[5] = new ToneMono(audioParams,this.args,melody);audioObjects[6] = new TonesStereo(audioParams,this.args,melody);audioObjects[7] = new WhiteNoise(audioParams,this.args,melody);//Select an audio object at random and call the getMelody method on// the object. Random randomGenerator = new Random();int randomIndex = randomGenerator.nextInt(8); System.out.println("randomIndex = " + randomIndex);System.out.println(audioObjects[randomIndex].getClass());melody = audioObjects[randomIndex].getMelody(); //Play or file the audio datanew AudioPlayOrFile01(audioParams,melody,this.args[0]).playOrFileData();}//end constructor //-------------------------------------------------------------------------//}//end class MusicComposer08.java //===========================================================================//

Questions & Answers

what is Economics
Ebem Reply
the branch of knowledge concerned with the production, consumption, and transfer of wealth and has Influence by sociology!!!!
Ajay
Economics is the study of how humans make decisions when they want to fulfil their requirements and desires for goods, services and resources.
Abdullah
Economics is the study how humans make decisions in the faces of scarcity.
Rose
economic is the study of how human make decision in the fact of scarcity.
Toang
Economics is a social science which study human behavior as a relationship between earn and scarce mean which have alternative uses
Juliet
what is market structure
Fatima
what is demand
Gooluck Reply
demand is the willingness to purchase something
Mohamed
demand is the potential ability or williness to purchases something at a particular price at a given period of time..
Ahmed
Demand refers to as quantities of a goods and services in which consumers are willing and able to purchase at a given period of time. Demand can also be defined as the desire backed by ability to purchase .
Fadiga
what is demand
John Reply
is the production of goods in scarcity
David
thanks
John
Demand refers to as quantities of a goods and services in which consumers are willing and able to purchase at a given period of time.
Fadiga
what is demand of supply
music Reply
What is the meaning of supply of labour
Anthonia Reply
what is production?
Elizabeth Reply
Production is basically the creation of goods and services to satisfy human wants
Anthonia
under what condition will demand curve slope upward from left to right instead of normally sloping downward from left to right
Atama Reply
how i can calculate elasticity?
Tewekel Reply
What is real wages
Emmanuella Reply
what are the concept of cost
Tabitha Reply
what is the difference between want and choice
Grace Reply
Want is a desire to have something while choice is the ability to select or choose a perticular good or services you desire to have at a perticular point in time.
Dalton
substitutes and complements
Amman Reply
Substitute are goods that can replace another good but complements goods that can be combined together
nkanyiso
account for persistent increase in lnflation
niwahereza Reply
what is opportunity cost
Adebowale Reply
opportunity cost reffered to as alternative foregone when choice is made
niwahereza
government measures to control inflation?
Formu Reply
control populationk growth rate by using family planning to reduce faster increase of people than job creation
niwahereza
in a comparison of the stages of meiosis to the stage of mitosis, which stages are unique to meiosis and which stages have the same event in botg meiosis and mitosis
Leah Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Accessible objected-oriented programming concepts for blind students using java. OpenStax CNX. Sep 01, 2014 Download for free at https://legacy.cnx.org/content/col11349/1.17
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible objected-oriented programming concepts for blind students using java' conversation and receive update notifications?

Ask