<< Chapter < Page Chapter >> Page >

The instance variable named melody will ultimately refer to an array object that holds the audio data that will be played or filed.

The instance variable named args will ultimately refer to an array object that holds an incoming command-line parameter.

Command-line parameters

Only one command-line parameter is needed and it is optional. If the value of the parameter is "play", the sound will be played immediately. Otherwise, theparameter string will be used as a filename for an audio file of type AU. In this case,it must be a string that would be valid as a file name for your operating system.

The main method

The main method simply instantiates a new object of this class passing the incoming args array's reference to the constructor.

Compiling and executing the program

I typically use Windows batch files to compile and execute my Java program. Listing 2 shows the contents of such a batch file. This batch file will attempt to:

  • Delete all class files in the folder.
  • Delete a file named WhiteNoise.au if it exists.
  • Compile the program.
  • Execute the program once to play the sound immediately.
  • Execute the program again to write the sound to the audio file named WhiteNoise.au.
  • Delete all the class files in the folder.
Listing 2 . The file named WhiteNoise.bat.
echo off del *.classdel WhiteNoise.au echo onjavac MusicComposer04.java java MusicComposer04 playjava MusicComposer04 WhiteNoise echo offdel *.class pause

The constructor for MusicComposer04

Listing 3 shows the beginning of the constructor for MusicComposer04 .

Listing 3 . Beginning of the constructor for MusicComposer04.
public MusicComposer04(String[] args){//constructorthis.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

The constructor begins by saving the incoming reference to the args array containing the command-line parameter.

If the length of the args array is zero, this means that the user did not enter a command-line parameter. In that case, the constructor instantiates an appropriate arrayobject, populates its only element with a reference to a "play" string, and saves that array object's reference in the instance variable discussed earlier .

Get and play or file the sound

Listing 4 instantiates a new object of the WhiteNoise class and saves the object's reference in a local reference variable of type WhiteNoise named whiteNoise . You are already familiar with the three parameters that are passed to the constructor for the WhiteNoise class.

(Later when we discuss runtime polymorphism, we will save such an object's reference in a reference variable of type AudioSignalGenerator02 , which is the immediate superclass of the WhiteNoise class.)

Listing 4 . Get and play or file the sound.
//Get a populated array containing audio data for white or pink noise. WhiteNoise whiteNoise = new WhiteNoise(audioParams,this.args,melody);melody = whiteNoise.getMelody(); //Play or file the audio datanew AudioPlayOrFile01(audioParams,melody,this.args[0]).playOrFileData();}//end constructor //-------------------------------------------------------------------------//}//end class MusicComposer04.java

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
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