<< 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

if three forces F1.f2 .f3 act at a point on a Cartesian plane in the daigram .....so if the question says write down the x and y components ..... I really don't understand
Syamthanda Reply
hey , can you please explain oxidation reaction & redox ?
Boitumelo Reply
hey , can you please explain oxidation reaction and redox ?
Boitumelo
for grade 12 or grade 11?
Sibulele
the value of V1 and V2
Tumelo Reply
advantages of electrons in a circuit
Rethabile Reply
we're do you find electromagnetism past papers
Ntombifuthi
what a normal force
Tholulwazi Reply
it is the force or component of the force that the surface exert on an object incontact with it and which acts perpendicular to the surface
Sihle
what is physics?
Petrus Reply
what is the half reaction of Potassium and chlorine
Anna Reply
how to calculate coefficient of static friction
Lisa Reply
how to calculate static friction
Lisa
How to calculate a current
Tumelo
how to calculate the magnitude of horizontal component of the applied force
Mogano
How to calculate force
Monambi
a structure of a thermocouple used to measure inner temperature
Anna Reply
a fixed gas of a mass is held at standard pressure temperature of 15 degrees Celsius .Calculate the temperature of the gas in Celsius if the pressure is changed to 2×10 to the power 4
Amahle Reply
How is energy being used in bonding?
Raymond Reply
what is acceleration
Syamthanda Reply
a rate of change in velocity of an object whith respect to time
Khuthadzo
how can we find the moment of torque of a circular object
Kidist
Acceleration is a rate of change in velocity.
Justice
t =r×f
Khuthadzo
how to calculate tension by substitution
Precious Reply
hi
Shongi
hi
Leago
use fnet method. how many obects are being calculated ?
Khuthadzo
khuthadzo hii
Hulisani
how to calculate acceleration and tension force
Lungile Reply
you use Fnet equals ma , newtoms second law formula
Masego
please help me with vectors in two dimensions
Mulaudzi Reply
how to calculate normal force
Mulaudzi
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