<< Chapter < Page
  Accessible objected-oriented     Page 11 / 17
Chapter >> Page >
Listing 16 . Beginning of the getPiano method.
Hashtable getPiano(){Hashtable piano = new Hashtable();double factor = 1.05946309436;//12th root of 2//Define the name and frequency of the first note. double freq = 110;//Frequency of A2 at 110 Hz. Start with this.String note = "A2";//Name of note at 110 Hz. Start with this.//Used to parse a note into 3 single-character substrings such // as C, 5, and #.String sub1 = null; String sub2 = null;String sub3 = null;

The first half of the code in Listing 16 is completely straightforward.

The number in the center of the note names (such as A3#) changes at C and not at A. Also, the # character appears on some notes andnot on all notes. As a result, it is difficult to use a loop structure to deal with the names of the notes.

I will decompose each note into two or three substrings for processing. In other words, the note name "A2" will be decomposed into an"A" and a "2". The note name "C5#" will be decomposed into a "C", a "5", and a "#". The last three variables that are declared in Listing 16 will be used to save those strings.

Store the current note and compute the frequency of the next note

The process of populating the Hashtable object with note names and frequencies is controlled by a for loop that begins in Listing 17 .

Listing 17 stores the name and frequency for the current note and computes the frequency of the next note. ( The initial name and frequency for the current note were defined in Listing 16 .) The frequency of the next note is computed by multiplying the frequency of the current note bythe twelfth root of two, which is stored in the variable named factor.

Listing 17 . Store the current note and compute the frequency of the next note.
for(int cnt = 0;cnt<61;cnt++){ //This loop counts from A1 through A7 at 3520 Hz. //Store the name and the frequency of the note in the next element in// the hashtable. piano.put(note,freq);//Compute the frequency of the next notefreq *= factor;

Construct the name of the next note

While it may be possible to write a loop structure to deal with note names, it was not obvious to me how to do that. Therefore, I took a brute forceapproach and wrote a long and tedious block of logic code to do the job.

Listing 18 shows the logic used to decompose the name of the current note into two or three single-character strings and to use those strings to constructthe name of the next note. That note will be the current note at the top of the next iteration and will be saved, along with the frequency in the Hashtable object. I will leave it as an exercise for the student to understand and possibly improve on this logic.

Listing 18 . Construct the name of the next note.
//Use logic to construct the name of the next note in a sequence such // as A2,A2#,B2,C3,C3#,D3,D3#,E3,F3,F3#,G3,G3#,A3, etc.//Begin by parsing the current note name into three single-character // substrings, the third of which may be null.if(note.length() == 3){ sub1 = note.substring(0,1);sub2 = note.substring(1,2); sub3 = note.substring(2,3);}else{ sub1 = note.substring(0,1);sub2 = note.substring(1,2); sub3 = null;}//end if//Use the three substrings of the current note name to determine the // name of the next note. This is long and tedious but it works.if((sub1.equals("A"))&&(sub3 == null)){ sub1 = "A";sub3 = "#"; }else if((sub1.equals("A"))&&(sub3.equals("#"))){ sub1 = "B";sub3 = null; }else if((sub1.equals("B"))){sub1 = "C"; sub3 = null;//Increment the number sub2 = "" + (1 + Integer.parseInt(sub2));}else if((sub1.equals("C"))&&(sub3 == null)){ sub1 = "C";sub3 = "#"; }else if((sub1.equals("C"))&&(sub3.equals("#"))){ sub1 = "D";sub3 = null; }else if((sub1.equals("D"))&&(sub3 == null)){ sub1 = "D";sub3 = "#"; }else if((sub1.equals("D"))&&(sub3.equals("#"))){ sub1 = "E";sub3 = null; }else if((sub1.equals("E"))){sub1 = "F"; sub3 = null;}else if((sub1.equals("F"))&&(sub3 == null)){ sub1 = "F";sub3 = "#"; }else if((sub1.equals("F"))&&(sub3.equals("#"))){ sub1 = "G";sub3 = null; }else if((sub1.equals("G"))&&(sub3 == null)){ sub1 = "G";sub3 = "#"; }else if((sub1.equals("G"))&&(sub3.equals("#"))){ sub1 = "A";sub3 = null; }else{System.out.println("Can't reach this point."); }//end else//Construct the next note from the updated substrings. if(sub3 == null){note = sub1 + sub2; }else{note = sub1 + sub2 + sub3; }//end if}//end for loop return piano;}//end getPiano }//end class PlayerPiano01

Questions & Answers

Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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