Results 1 to 3 of 3
  1. #1
    MrShazzyMan is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Default Java programming assignment

    Hi all,

    I am a proper 'noobie' too all the java programming stuff and I've not even got the hang of it yet and I already have an assignment which my tutor claims is easy, well it sounds easy to understand but writing the code for the assignment makes me feel lost. So here goes...

    Basically I have a bunch of DTM (digital terrain management) files that read to be read by the java programming code. The tutor says that if I can complete the task for this coding below I can use this code by modifying it a little to be able to read in DTM files but HOW on earth do I do this? What things should I be looking at to put into the final piece of code to be able to read the DTM files and find out specific bits of information from the DTM files. SOMEONE PLEASE HELP !

    package uk.ac.mmu.cnt.one.arrays;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    public class Exploration {
    /**
    * the main method for our oil exploration program
    *
    * @param args
    * @throws IOException
    */
    public static void main(String[] args) throws IOException {
    // declare some variables
    int nRows = 8;
    int nCols = 8;
    // declare some tables
    double data [][] = new double[nRows][nCols];
    char map [][] = new char[nRows][nCols];
    // open the file for reading
    String fileName = "readings.dat";
    BufferedReader file = new BufferedReader(new FileReader(fileName));
    // read data into the data array
    for (int i = 0; i < nRows; i++) {
    // read the line and split it up into individual readings
    String row [] = file.readLine().split(" ");
    // write the data into the data array
    for (int j = 0; j < nCols; j++) {
    data[i][j] = Double.parseDouble(row[j]);
    }
    }
    // close file after having read the data in
    file.close();
    // initialise the map table to be all blank
    for (int i = 0; i < nRows; i++) {
    for (int j = 0; j < nCols; j++) {
    map[i][j] = 'o';
    }
    }// assess each point (we exclude the points on the border as we can't
    // easily calculate an average of all neighbours for those points)
    for (int i = 1; i < (nRows - 1); i++) {
    for (int j = 1; j < (nCols - 1); j++) {
    // calculate the average of the neighbouring points to the
    // north, west, east and south
    double sum = data[i-1][j] + data[i][j-1] + data[i][j+1] +
    data[i+1][j];
    double average = sum / 4;
    // now, work out whether it is a likely spot
    if (data[i][j] > average) {
    map[i][j] = 'x';
    }
    }
    }
    // display results
    for (int i = 0; i < nRows; i++) {
    for (int j = 0; j < nCols; j++) {
    System.out.print(map[i][j] + " ");
    }
    System.out.println();
    }
    }
    }

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,928
    Rep Power
    19

    Default Re: Java programming assignment

    Please wrap your code in [code] tags [/code] otherwise it is very hard to read.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Java programming assignment

    Also, go through the Forum Rules, particularly the third paragraph. To edit the subject line, click "Edit Post" and then "Go Advanced"

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

Similar Threads

  1. help..stuck w/ a java programming assignment
    By clemsontigers in forum New To Java
    Replies: 16
    Last Post: 02-19-2014, 04:16 AM
  2. Replies: 15
    Last Post: 04-21-2012, 01:38 AM
  3. Replies: 2
    Last Post: 01-19-2012, 07:43 PM
  4. assistance w/ java programming assignment
    By clemsontigers in forum New To Java
    Replies: 4
    Last Post: 04-07-2011, 08:07 PM
  5. Replies: 9
    Last Post: 03-06-2011, 03:00 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
  •