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();
}
}
}
Re: Java programming assignment
Please wrap your code in [code] tags [/code] otherwise it is very hard to read.
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