1
findAbbreviation(atomiC#)
에 대한 방법을 시작하는 방법을 이해하는 데 문제가 있습니다. 다른 방법으로 table[]
을 사용하려고 할 때마다 정적 변수가 아닌 문제가 발생합니다. 약어가있는 요소에 대한 참조를 반환하는이 메서드를 시작하는 방법에 대한 모든 정보를 공유하십시오.Java는이 방법으로 어디에서 시작 해야할지 알지 못합니다.
public class PeriodicTable {
private final static int MAX_ELEMENTS = 150;
private PeriodicElement[] table;
private int actualSize;
public PeriodicTable() throws IOException {
table = new PeriodicElement[MAX_ELEMENTS];
Scanner input = new Scanner(new File("/user/tvnguyen7/data/periodictable.dat"));
int index = 0;
while(input.hasNext() && index < MAX_ELEMENTS) {
int aN = input.nextInt();
String abbr = input.next();
String name = input.next();
double aW = input.nextDouble();
table[index] = new PeriodicElement(aN, abbr,name, aW);
index++;
}
input.close();
actualSize = index;
}
public void printTable() throws IOException {
final int MAX_ELEMENTS = 118;
Scanner input = new Scanner(new File("/user/tvnguyen7/data/periodictable.dat"));
int[] atomicNumbers = new int[MAX_ELEMENTS];
double[] atomicWeights = new double[MAX_ELEMENTS];
for(int i=0;i<atomicNumbers.length;i++) {
atomicNumbers[i]= input.nextInt();
String abbreviation = input.next();
String name = input.next();
atomicWeights[i] = input.nextDouble();
System.out.printf("%4d %-4s %-25s %.2f\n" , atomicNumbers[i], abbreviation, name, atomicWeights[i]);
}
input.close();