📄 goldexploration.java
字号:
import java.io.*;
import javagently.*;
import myutilities.*;
class GoldExploration {
/* The Gold class by J M Bishop Jan 1997
* Java 1.1 October 1997
* Transforms raw geological readings into a character map of a
* possible gold reef.
* Illustrates two different multi-dimensional arrays in a class.
*/
int rowMax = 8;
int colMax = 8;
char map [][] = new char[rowMax][colMax];
double data [][] = new double[rowMax][colMax];
char blank = ' ';
char cover = '*';
Stream fin;
GoldExploration () throws IOException{
introduction();
getData();
assess();
report();
}
public void getData() throws IOException {
for (int i = 0; i < rowMax; i++)
for (int j = 0; j < colMax; j++)
data[i][j] = fin.readDouble();
}
public void assess() {
double point, average;
for (int i = 0; i < rowMax; i++) {
for (int j = 0; j < colMax; j++) {
map[i][j] = blank;
}
}
for (int i = 1; i < rowMax-1; i++) {
for (int j = 1; j < colMax-1; j++) {
point = data[i][j];
average = (data[i-1][j] + data[i+1][j] +
data[i][j-1] + data[i][j+1]) / 4;
if (point > average)
map[i][j] = cover;
}
}
}
public void report() {
System.out.println("Map of possible boundaries of the " +
"gold reef");
System.out.println("===================================" +
"========");
System.out.println();
System.out.print(" ");
for (int j = 0; j < colMax; j++) {
System.out.print(j+" ");
}
System.out.println();
for (int i = 0; i < rowMax; i++) {
System.out.print(i+" ");
for (int j = 0; j < colMax; j++)
System.out.print(map[i][j]+" ");
System.out.println();
}
System.out.println("Good luck prospecting!");
}
void introduction () throws IOException {
System.out.println("******* Savanna Exploration Inc. *****");
System.out.println("Will use test data in gold.dat"+
" if file open is unsuccessful");
fin = Filer.open("");
System.out.println("We shall find gold!\n");
}
public static void main(String[] args) throws IOException {
new GoldExploration ();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -