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

I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
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