Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By jim829

Thread: Look up table for Do, Re, Mi notes?

  1. #1
    Drew345 is offline Member
    Join Date
    May 2015
    Posts
    31
    Rep Power
    0

    Default Look up table for Do, Re, Mi notes?

    I have a table of music notes and values:

    {"Do":262,"Re":294,"Mi":330,"Fa":349,"Sol":392,"La ":440,"Si":494}

    Is there some way I can make that some kind of "list" or even object, where I can then use the string "Mi" to get back the number that is the frequency of that note?

    I guess I am looking for what to put in for the ???? here in this snippit (or maybe this is totally off base)

    string notename = "Mi";
    int notefreq;

    ????? tableofnotes={"Do":262,"Re":294,"Mi":330,"Fa":349, "Sol":392,"La":440,"Si":494}

    notefreq=???? (tableofnotes,notename)

    Any help appreciated!!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Look up table for Do, Re, Mi notes?

    One way would be to parse the Strings in that list of Strings separating the names and values and then use them with a Map<String, Integer>
    Then the value could be accessed using the get method:
    int freq = theMap.get("Mi");
    Last edited by Norm; 04-09-2017 at 01:23 PM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Look up table for Do, Re, Mi notes?

    Well, for something like this where the values wouldn't (shouldn't change) I would use an Enum. Check it out here

    Regards,
    Jim
    quad64bit likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. JSP Notes
    By chandrasekhar.melam in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 07-19-2013, 06:04 PM
  2. Replies: 1
    Last Post: 09-27-2011, 06:06 AM
  3. Parsing Help - With Notes
    By BordomSUCKS in forum New To Java
    Replies: 6
    Last Post: 06-09-2011, 09:59 AM
  4. Form Notes
    By creel in forum Java Applets
    Replies: 0
    Last Post: 02-02-2008, 01:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •