Results 1 to 5 of 5
  1. #1
    devanb3 is offline Member
    Join Date
    Jul 2012
    Rep Power

    Default School work help asap

    I have a project due for my programming class i have part of it done but cannot figure out the main part how to get the alphanumeric part to work here are the assignments

    here is my code as of now
    Java Code:
    import java.util.Scanner;  
    import javax.swing.JFileChooser;  
    public class PlayThatTune {  
        public static Scanner openFileFromDialog() {  
            Scanner scan = null;  
            JFileChooser openChooser = new JFileChooser(System.getProperties()  
            int retval = openChooser.showOpenDialog(null);  
            if (retval == JFileChooser.APPROVE_OPTION) {  
                File file = openChooser.getSelectedFile();  
                try {  
                    scan = new Scanner(file);  
                } catch (FileNotFoundException e) {  
            } else  
                System.out.println("File open canceled.");  
            return scan;  
    public static void main(String[] args) throws FileNotFoundException{  
            Scanner in = openFileFromDialog();  
            while (in.hasNext()) {  
                int pitch = in.nextInt();  
                double duration = in.nextDouble();  
                System.out.print(pitch + " " + duration + "\n");  
                double[] a = note(pitch, duration);  
        public static double[] tone(double hz, double t) {  
            int sps = 44100;  
            int N = (int) (sps * t);  
            double[] a = new double[N+1];  
            for (int i = 0; i <= N; i++)  
                a[i] = Math.sin(2 * Math.PI * i * hz / sps);  
            return a;  
        public static double[] note(int p, double t) {  
            double hz = 440 * Math.pow(2, p / 12.0);  
            double[] a = tone(hz, t);  
            double[] hi = tone(2*hz, t);  
            double[] lo = tone(hz/2, t);  
            double[] h = sum(hi, lo, .5, .5);  
            return sum(a, h, .5, .5);  
        public static double[] sum(double[] a, double[] b, double awt, double bwt) {  
            double[]c = new double[a.length];  
            for(int i = 0; i < a.length; i++)  
                c[i] = a[i] * awt + b[i] * bwt;  
            return c;  

  2. #2
    awinston is offline Student
    Join Date
    Jul 2012
    United States
    Rep Power

    Default Re: School work help asap

    The members of this forum are not responsible for doing your homework. If you have a specific question, then I'm sure someone would be happy to help you.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  3. #3
    devanb3 is offline Member
    Join Date
    Jul 2012
    Rep Power

    Default Re: School work help asap

    im not asking for someone to do it guidance on how to do the final part is all i cannot figure out how to get the alphanumeric .txt files to play as sounds is my issue not trying to get someone to do the work just help with figuring it out

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: School work help asap

    First off, people won't go to random websites to read up on assignments.
    You need to tell us what the code is doing, and what it is supposed to be doing.
    Where it is going wrong.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: School work help asap

    Also, please go through the Forum Rules -- particularly the third paragraph.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Please Help ASAP!
    By PleaseHelp in forum New To Java
    Replies: 5
    Last Post: 04-24-2012, 02:25 PM
  2. Please help me ASAP!
    By Asvin in forum New To Java
    Replies: 13
    Last Post: 05-17-2011, 05:55 PM
  3. Need help ASAP, please
    By KAM0002 in forum New To Java
    Replies: 6
    Last Post: 12-08-2010, 04:58 PM
  4. Need some help ASAP
    By varma in forum New To Java
    Replies: 11
    Last Post: 01-08-2010, 12:15 AM
  5. Need help with school work
    By ccfdet in forum New To Java
    Replies: 3
    Last Post: 08-29-2009, 07:14 PM

Posting Permissions

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