<< 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 phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
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