Can someone test a prog for me, and help reading from an exty file

Okay, I have a program to calculate the Pearson product-moment correlation coefficient ( http://en.wikipedia.org/wiki/Pearson_correlation_coefficient ) from an external file that I've just written for an assignment on Monday.
I can't actually run it because I can't find a machine with Java on that works, though I can compile it. Why is a long story, but University Admin are going to feel my wrath.
I would like two things.
1) would someone be kind enough to try to run it and test it in anyway and report any bugs or inadequacies back to me. (you will need to create a text file called data.dat with some numbers in, e.g.
14.234 54.4534
376.56 432.2332
23432. 23234.23
2) How can I can the computer to ask the user to enter either a) the name of the file from system.in or b) from a popup dialogue box with a browse feature (or is that incompatible with some OSs?).
The file follows:
// Import packages
     import java.io.*; // Import all the Java input/output packages
     import java.util.StringTokenizer; // Import a utility package
class Pearsontwo
public static void main (String[] args)
     /* Define variables.
          (double any number with decimal point.
          ints take integer value) */
          double     sumx, sumy,               // sum of x and sum of y
                    sumxx, sumyy,          // sum of x squared and y squared
                    sumxy;                    // sum of products of x and y
          int n;                              // n is number of lines
     // Set name of file to be read
          String fileName = data.dat; // define the name of the file
     //     (Enhancement: use user input. This requires the use of System.in which is a bit complicated.
          //System.out.print("Please type the name of the file you wish to run the analysis on:");
          //fileName = TextIO.getInt();
     // Set things for reading external file
BufferedReader br;     // Will be used to read the file
String line;          // Will be used to hold a line read from the file
StringTokenizer st; // Will be used to break a line into separate words
          String firstWord, secondWord;     // File will be read as string type
double firstNumber, secondNumber;     // that need to be converted into numbers.
try // if an error occurs, go to the "catch" block below
// Create a buffered file reader for the file
     br = new BufferedReader (new FileReader(fileName));
// Continue to read lines whilst there is one or more left to read
                    while (br.ready())
                    {   line= br.readLine();               // Read one line of the file
                         st = new StringTokenizer(line);     // Prepare to split the line into "words"
                         // Get the first two words (invalid --> error --> catch)
                              firstWord = st.nextToken();
                              secondWord = st.nextToken();
                         // Turn words into numbers (invalid --> error --> catch)
                              firstNumber = Double.parseDouble(firstWord);
                              secondNumber = Double.parseDouble(secondWord);
                         // Add the numbers to the previously stored numbers
                              sumx = sumx + firstNumber;
                              sumy = sumy + secondNumber;
                              sumxx = sumxx + (firstNumber * firstNumber);
                              sumyy = sumyy + (secondNumber * secondNumber);
                              n = n++; add one to the value of n.
// Close the file
br.close();
// Handle any error in opening the file
               catch (Exception e)
               {   System.err.println("File input error.\nPlease amend the file " + fileName);
          //     Calcuate r in stages, variance and covariance first.
               double variancex = (sumx2 - (sumx * sumx / n)) / (n - 1);     // calculates the variance of x ...
               double variancey = (sumx2 - (sumx * sumx / n)) / (n - 1);     // ... and y
               double covariance = (sumx * sumy - sumx * sumy / n ) / (n - 1);     // and the covariance of x and y
               double r = covariance / Math.sqrt(variancex * variancey);     // and the Pearson r value
               // Printout
               System.out.print("The Pearson product-moment correlation for these data is:" );
               System.out.println ( r );
               // Also print to file ?
Cheers,
Duncan.
(Note: this is my own work by Duncan Harris at Cariff University, so I'm not plaigerising anyone other than myself if I post it here and it subsequently gets found by one of the course organisers who have given permission for this sort of thing anyway!)

"I can't actually run it because I can't find a machine with Java on that works, though I can compile it. Why is a long story, but University Admin are going to feel my wrath."
I'm sure they're worried.
I don't understand this. You can compile, but not run? This makes no sense at all.
Why can't you simply download the JDK from Sun and install it on a machine? You could both compile and run then.
You don't need a pop-up dialog box to get an input file name from a user. The command prompt is quite sufficient.

Similar Messages

  • Urgent help for processing XML stream read from a JAR file

    Hi, everyone,
         Urgently need your help!
         I am reading an XML config file from a jar file. It can print out the result well when I use the following code:
    ===============================================
    InputStream is = getClass().getResourceAsStream("conf/config.xml");
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line;
    while ((line = br.readLine()) != null) {
    System.out.println(line); // It works fine here, which means that the inputstream is correct
    // process the XML stream I read from above
    NodeIterator ni = processXPath("//grid/gridinfo", is);
    Below is the processXPath() function I have written:
    public static NodeIterator processXPath(String xpath, InputStream byteStream) throws Exception {
    // Set up a DOM tree to query.
    InputSource in = new InputSource(byteStream);
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    dfactory.setNamespaceAware(true);
    Document doc = dfactory.newDocumentBuilder().parse(in);
    // Use the simple XPath API to select a nodeIterator.
    System.out.println("Querying DOM using " + xpath);
    NodeIterator ni = XPathAPI.selectNodeIterator(doc, xpath);
    return ni;
    It gives me so much errors:
    org.xml.sax.SAXParseException: The root element is required in a well-formed doc
    ument.
    at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213
    at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XM
    LDocumentScanner.java:570)
    at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.endO
    fInput(XMLDocumentScanner.java:790)
    at org.apache.xerces.framework.XMLDocumentScanner.endOfInput(XMLDocument
    Scanner.java:418)
    at org.apache.xerces.validators.common.XMLValidator.sendEndOfInputNotifi
    cations(XMLValidator.java:712)
    at org.apache.xerces.readers.DefaultEntityHandler.changeReaders(DefaultE
    ntityHandler.java:1031)
    at org.apache.xerces.readers.XMLEntityReader.changeReaders(XMLEntityRead
    er.java:168)
    at org.apache.xerces.readers.UTF8Reader.changeReaders(UTF8Reader.java:18
    2)
    at org.apache.xerces.readers.UTF8Reader.lookingAtChar(UTF8Reader.java:19
    7)
    at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.disp
    atch(XMLDocumentScanner.java:686)
    at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
    canner.java:381)
    at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.
    java:195)
    at processXPath(Unknown Source)
    Thank you very much!
    Sincerely Yours
    David

    org.xml.sax.SAXParseException: The root element is required in a well-formed document.This often means that the parser can't find the document. You think it should be able to find the document because your test code could. However if your test code was not in the same package as your real (failing) code, your test is no good because getResourceAsStream("conf/config.xml") is looking for that file name relative to the package of the class that contains that line of code.
    If your test code wasn't in any package, put a slash before the filename and see if that works.

  • Can someone sum up compressor for me and what you'd use it for?

    Mac G5   Mac OS X (10.4.7)  

    http://www.apple.com/finalcutstudio/compressor/
    http://www.apple.com/finalcutstudio/compressor/encoding.html
    http://www.apple.com/finalcutstudio/compressor/conversions.html
    http://www.apple.com/finalcutstudio/compressor/batch.html
    http://www.apple.com/finalcutstudio/compressor/distribute.html
    http://www.apple.com/finalcutstudio/specs.html?compressor
      Alberto

  • Can someone please decipher this for me

    hello I am a student and up to this poit being my second year in java I have not had any problems. I am working on an asignment but my teacher is away and I don't understand exactly what his assignment asks for. Can someone briefly decipher it for me, any help would be appreciated.
    here it is:
    Define three classes with the following functions and relationship
    among them:
    The class Thought contains a method message which implements to print out the message �I�m a teacher.�;
    The class Advice is a subclass of the class Thought. The class Advice also contains a method message, the name is the same as its
    superclass�, however the method message of class Advice is to print
    out different message �I�m your student.�;
    The class Messages contains a main method and it should instantiate two instances, one is from the class Thought and the other is from the class Advice.

    We're not going to do this for you, but the problem is simple. It may help you to start by drawing what you want on paper.
    You need three classes, named Thought, Advice and Message.
    Thought and Advice each have a method that prints a message, perhaps called printMessage().
    Advice extends Thought.
    Message contains your main method, within which you will create one instance of Advice, and one of Thought.
    The point of the practical is to show how the method in Advice overrides the method in Thought. I am, however disbelieving of the assertion that this is a 2nd year Java practical - it's the kind of thing I'd expect you to tackle after the first lecture.
    (Note that this is merely a rewording of your practical text)

  • For some reason the system is telling me my birth date is wrong when it's not and it won't let me proceed to reset my password. Can someone tell me how to get a "real" person from tech on line?

    For some reason the system is telling me my birth date is wrong when it's not and it won't let me proceed to reset my password. Can someone tell me how to get a "real" person from tech on line?

    contact itunes support

  • I have an apple tv 1st generation, and there is a setting for airtunes. can someone tell me what this is and how to use it?

    I have an apple tv 1st generation, and there is a setting for airtunes. can someone tell me what this is and how to use it?

    I've looked at that, but on my PC, "look for remote speakers connected with airtunes" isn't an option.
    The only options I get are "prevent ipods [etc] from syncing automatically" , "warn me when [X %] of the data on this computer will be changed" and "forget all remotes". Its also got a list of backups I have saved, as well as a button to reset sync history.
    When I am playing a song, the "airplay" button isn't even visible.
    I am sure that the apple tv setting is on as well. Is there anything else you can help me with?

  • Can someone else try to compile this and see why the program is returning..

    Can someone else try to compile this and see why the program is returning "false" when I try to delete the files on exit (at bottom of code)... I have the source code uploaded to the web as well as my 2 text test files inside a zip file(they need to be unzipped so you can try to test the program) and .class file... the program works the way i want it to, but i just can't seem to delete the 3 temporary files i use... why??? why does it return false???
    Thanks in advance,
    Disco Hristo
    http://www.holytrinity-holycross.org/DiscoHristo/Assemble.java
    http://www.holytrinity-holycross.org/DiscoHristo/Assemble.class
    http://www.holytrinity-holycross.org/DiscoHristo/tests.zip
    * Assemble.java 1.0 02/06/22
    * @author Disco Hristo
    * @version 1.0
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class Assemble
         public static void main(String args[]) throws IOException
              if (args.length > 0) //     Checks to see if there are any arguments
                   printArgumentInfo ();
              else // if no arguments run the program
                   getInput ();
                   printToFile ();
                   deleteFiles ();
         public static void getInput () throws IOException
         //     Gets the input and then send it to 3 files according to Tags
              File head = new File ("head.chris");
    PrintStream headStream = new PrintStream (new FileOutputStream (head));
    File body = new File ("body.chris");
    PrintStream bodyStream = new PrintStream (new FileOutputStream (body));
    File foot = new File ("foot.chris");
    PrintStream footStream = new PrintStream (new FileOutputStream (foot));
    String input; //     String used to store input                
    File d = new File(".");
    String files[] = d.list();
    for (int n=0; n!=files.length; n++)
         if (files[n].endsWith(".txt") == true)
              String fileName = files[n];
              BufferedReader in = new BufferedReader (new FileReader(fileName));
                   while (true)
                   input = in.readLine();
                   if (input != null)
                        input = input.trim();
                        if (input == null) // if no more input                          
                             break;
                        else if ( (input.compareTo("<HEAD>")) == 0) // if start of <HEAD> text
                             do
                                  input = in.readLine();
                                       if (input != null)
                                       input = input.trim();
                                       if ( ((input.compareTo("<BODY>")) == 0) ||
                                                      ((input.compareTo("<FOOT>")) == 0) ||
                                                      ((input.compareTo("</BODY>")) == 0) ||
                                                      ((input.compareTo("</FOOT>")) == 0) ||
                                                      ((input.compareTo("<HEAD>")) == 0))
                                                      //checks to see if tags in input are in correct order
                                            System.out.println("Input Is Incorrectly Formatted - Tag Error");
                                            System.out.println("Close your <HEAD> tag before starting another tag.");
                                            System.exit(1); //exit program without printing data                                                   
                                       if ( (input.compareTo("</HEAD>")) != 0) //if not end of tag
                                            headStream.println(input); //print to text file
                             while ( (input.compareTo("</HEAD>")) != 0);
                        else if ( (input.compareTo("<BODY>")) == 0) // if start of <BODY> text
                             do
                                  input = in.readLine();
                                  if (input != null)
                                       input = input.trim();
                                       if ( ((input.compareTo("<HEAD>")) == 0) ||
                                                      ((input.compareTo("<FOOT>")) == 0) ||
                                                      ((input.compareTo("</HEAD>")) == 0) ||
                                                      ((input.compareTo("</FOOT>")) == 0) ||
                                                      ((input.compareTo("<BODY>")) == 0))
                                                      //checks to see if tags in input are in correct order
                                            System.out.println("Input Is Incorrectly Formatted - Tag Error");
                                            System.out.println("Close your <BODY> tag before starting another tag.");
                                            System.exit(1); //exit program without printing data                                                   
                                       if ( (input.compareTo("</BODY>")) != 0) //if not end of tag
                                            bodyStream.println(input); //print to text file
                             while ( (input.compareTo("</BODY>")) != 0);
                             else if ( (input.compareTo("<FOOT>")) == 0) // if start of <FOOT> text
                                  do
                                  input = in.readLine();
                                  if (input != null)
                                       input = input.trim();
                                       if ( ((input.compareTo("<BODY>")) == 0) ||
                                            ((input.compareTo("<HEAD>")) == 0) ||
                                                 ((input.compareTo("</BODY>")) == 0) ||
                                                 ((input.compareTo("</HEAD>")) == 0) ||
                                                 ((input.compareTo("<FOOT>")) == 0))
                                                 //checks to see if tags in input are in correct order
                                            System.out.println("Input Is Incorrectly Formatted - Tag Error");
                                            System.out.println("Close your <FOOT> tag before starting another tag.");
                                            System.exit(1); //exit program without printing data                                                   
                                       if ( (input.compareTo("</FOOT>")) != 0) //if not end of tag
                                                 footStream.println(input); //print to text file
                             while ( (input.compareTo("</FOOT>")) != 0);
                   else
                        break;
    public static void printToFile () throws IOException
    // Prints the text from head.txt, body.txt, and foot.txt to the output.log
         File head = new File ("head.chris");
         FileReader headReader = new FileReader(head);
              BufferedReader inHead = new BufferedReader(headReader);
              File body = new File ("body.chris");
              FileReader bodyReader = new FileReader(body);
              BufferedReader inBody = new BufferedReader(bodyReader);
              File foot = new File ("foot.chris");
              FileReader footReader = new FileReader(foot);
              BufferedReader inFoot = new BufferedReader(footReader);
              PrintStream outputStream = new PrintStream (new FileOutputStream (new File("output.log")));
              String output;     //string used to store output
              while (true)
                   output = inHead.readLine();
                   if (output == null) //if no more text to get from file
                   break;
                   else
                        outputStream.println(output); // print to output.log
              while (true)
                   output = inBody.readLine();
                   if (output == null)// if no more text to get from file
                   break;
                   else
                        outputStream.println(output); // print to output.log
              while (true)
                   output = inFoot.readLine();
                   if (output == null) //if no more text to get from file
                   break;
                   else
                        outputStream.println(output); // print to output.log
              //Close up the files
              inHead.close ();
              inBody.close ();
              inFoot.close ();
              outputStream.close ();     
         public static void printArgumentInfo () //     Prints argument info to screen
              System.out.println("");
              System.out.println("Disco Hristo");
              System.out.println("");
              System.out.println("Assemble.class is a small program that");
              System.out.println("takes in as input a body of text and then");
              System.out.println("outputs the text in an order according to");
              System.out.println("the tags that are placed in the input.");
         public static void deleteFiles ()
              File deleteHead = new File ("head.chris");
              File deleteBody = new File ("body.chris");
              File deleteFoot = new File ("foot.chris");
              deleteHead.deleteOnExit();
              deleteBody.deleteOnExit();
              deleteFoot.deleteOnExit();
    }

    I tired your program, it still gives false for files deleted. I tool the same functions you used in your program and ran it. The files get deleted. Tried this :
    <pre>
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class FileTest {
         public static void main(String args[]) {
              FileTest f = new FileTest();
              try {
                   f.createFile();
                   f.deleteFile();
              } catch(IOException ioe){
                   System.out.println(ioe.getMessage());
         public void createFile() throws IOException {
              System.out.println("In create file method...");
              File test = new File("test1.txt");
              File tst = new File("text2.txt");
              PrintStream testStream = new PrintStream (new FileOutputStream (test));
              PrintStream tstStream = new PrintStream (new FileOutputStream (tst));
              testStream.println("this is a test to delete a file");
              tstStream.println("this is the second file created");
              testStream.close();
              tstStream.close();          
         public void deleteFile() throws IOException {
              File test = new File("test1.txt");
              File tst = new File("text2.txt");
              System.out.println(test.delete());
              System.out.println(tst.delete());
    </pre>
    Also check the starting and closing braces for your if..else blocks.
    -Siva

  • Plerase can someone tell me why I cannot reinstall my upgrade from lightroom 4 (lightroom 3 installed off disc with serial no) my hard drive crashed, and I am trying to get lightroom 3; 4 and 5 back on so that I can link my catalogues and continue work. I

    Please can someone tell me why I cannot reinstall my upgrade from lightroom 4 (lightroom 3 installed off disc with serial no) my hard drive crashed, and I am trying to get lightroom 3; 4 and 5 back on so that I can link my catalogues and continue work. I cannot install lightroom 5 until the upgrades from 4 are on the pc, (lightroom 3 installed off disc but 4 is a copy of the upgrade download I got when I bought it) These serial no's are legit and  are registered under my account with adobe, but it still gives me the Big Red Cross when I put my serial no in! Please can someone help. I am at a loss. Thx Heidi

    BrightBluephotograph wrote:
    I cannot install lightroom 5 until the upgrades from 4 are on the pc,
    You don't need to have Lightroom 3 and 4 installed on your computer to install Lightroom 5.  Just install Lightroom 5 and input your serial number for 3 in the previous version box and your serial number for 5 in the upgrade box.

  • Do you have to sign personaly for a delivery or can someone else do it for you?

    do you have to sign personaly for a delivery or can someone else do it for you?

    someone else can do it for you. I recieved my MB air yesterday, and it was signed by my apartment office personnel.

  • I have multiple devices (imacs, lap tops and ipads) all connected to a NAS server.  Can I create a user for myself and one for my wife, and each have our own apple ID, and Itunes accounts, but all share the same media on NAS drives?

    I have multiple devices (iMacs, Lap tops, Ipads) all connected to a Nas Drive.  Can I create a user for myself and one for my wife and we each have our own apple ID's, Itunes etc, but share the same data on the hard drives?  So when she logs in, and sync's her ipads, they will sync with her stuff and when I do the same under my user account, on the same device, my ipads will sync with my stuff?

    You can share the same Apple ID for purchasng form the iTunes and app stores without any problems, but you should all used separate iCloud accounts with separate Apple IDs.  (You are not required to use the same ID for iCloud and other services as you do for the iTunes store.)  This will prevent you from ending up with merged data.  You should also use separate Apple IDs for iMessage and FaceTime or you will end up getting each other's text messages and FaceTime calls.
    This article may be of interest: http://www.macstories.net/stories/ios-5-icloud-tips-sharing-an-apple-id-with-you r-family/, as well as this video: http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l.

  • HT4436 how can i setup one account for me and my kids ?

    how can i setup one account for me and my kids ?

    One account each, or one account for all of you to share?
    Either way, follow the instructions here: http://www.apple.com/icloud/setup/
    Remember, if you share an iCloud account, you won't be able to maintain independent Contact lists, calendars, bookmarks etc. They will all be synced to all devices setup using the same account.

  • Can I have separate password for appstore and icloud email account?

    Can I have other password for appstore and icloud email account? Me and my girlfriend have iphones and i would like to share my apps with her, but i dont want to give her possibility to acces my email account....

    Well you can only have a different password if you are going to use a different Apple ID

  • I've been taking screen shots for years and opening them from my desktiop. Suddenly, today, I've lost the ability to open them. I can right click on the picture and do "quicklook", but that's it. They just won't open.   Similary, if I scan an image and sa

    I've been taking screen shots for years and opening them from my desktiop. Suddenly, today, I've lost the ability to open them. I can right click on the picture and do "quicklook", but that's it. They just won't open.
    Similary, if I scan an image and save it as a PDF file in pictures, I'm suddenly not able to open it either!
    Why?

    Move the com.apple.screencapture.plist file out of /username/Library/Preferences/ to the Desktop, log out and back in, and try again.
    BTW, use the default 10 point setting for text. Your choice just wastes screen space.

  • How can i get best practice for SD and MM

    Please, can any body tell me how can i get best practices for SD and MM for functional approach?
    Thanks
    Utpal

    Hello Utpal,
    I am really surprised, in just 10 minutes you searched that site and found it not useful. <b>Check out my previous reply "you will not find screen shot in this but you can add it in this"</b>
    You will not find readymade document, you need to add this as per your requirement.
    btw, the following link gives you some more link for new SAP guys, this will be helpful. <b>Check out HOW to BASIC transaction</b>
    New to Materials Management / Warehouse Management?
    Hope this helps.
    Regards
    Arif Mansuri

  • Which option do I have to select If I buy the latest iPad with cellular feature for international use? If I choose verizon can I just change the sim card and insert one from another country?

    Which option do I have to select If I buy the latest iPad with cellular feature for international use? If I choose verizon can I just change the sim card and insert one from another country?

    I would guess you need the A1460 model
    see here
    http://www.apple.com/ipad/LTE/

Maybe you are looking for

  • Creation of PM Notification based on UD Code

    Hi Seniors I am new to PM/QM module and facing an issue while configuring UD code follow-up actions. My requirement is once the Valution Code is set to "Rejected" in UD code then follow-up action should be generated and in this follow up action, coup

  • Upgrading Multiple Phones on a Family Plan

    I have been reading through posts on these forums and have yet to find a concrete answer to my situation. My wife and I have the nationwide family talk 700 plan and she is the primary number. When I login to our account online, it says that we only h

  • Colors showing incorrectly after convert

    Hi, I edited my CR2 pictures in Lightroom. After converting to any format the colors were colder than in original image. I opened it in Photoshop, Irfanview and Firefox. In Lightroom the image looked same as original. Both Lightroom and Photoshop are

  • Problem with Export - Image Sizing

    Hello, I'm running LR3 on a relatively new iMac.  I am using LR to edit RAW photos from my Nikon D700 and one of the things I do is export to .jpg to put some photos on my website.  To do this, each photo must be the same width and height, or it caus

  • Getting  SCAC-50012 while deploying the workflow

    Hi, I have embedded java code in my workflow. While deploying the workflow it throws the SCAC-50012 error. Please suggest the reason for this issue.