ゴルファー(practice.txt)の名前、年齢、得点情報を入力ファイルに取り込むプログラムを作成する必要があります。このファイルは、特定の年齢層の得点と比較する必要があります。たとえば、マニーは14歳なので、12-15歳の年齢層のパースコアに従います。マニーはホール1で5を撃ったので、彼はパーになった。ファイルと配列を比較する方法を理解できませんでしたか?私の方法で私を得るためのコードやアイディアはすばらしいでしょう。文字列ファイルをint型として配列に読み込みますか?
入力ファイルpractice.txt:
ジェイ57 4 3 2 3 5 3 2 3 4
グロリア39 4 4 3 3 4 4 3 3 5
マニー14 5 6 4 6 5 6 4 4 6
ジョー3 9 8 8 7 6 6 7 5 7
パーのスコアがチャート:
HOLES
AGE 1 2 3 4 5 6 7 8 9
4 and under 8 8 9 7 5 7 8 5 8
5 – 7 7 7 8 6 5 6 7 5 6
8 – 11 6 5 6 5 4 5 5 4 5
12 – 15 5 4 4 4 3 4 3 3 4
16 and over 4 3 3 3 2 3 2 3 3
私が持っているもの:
import java.io.File;
import java.util.Scanner;
import java.util.List;
import java.io.FileNotFoundException;
import java.util.ArrayList;
public class imTryingHere {
public static void main (String[] args) throws FileNotFoundException
{
int [][] ageGroups =
{
{4},
{7},
{11},
{15},
{100},
};
int[][] holePars=
{
{8,8,9,7,5,7,8,5,8},
{7,7,8,6,5,6,7,5,6},
{6,5,6,5,4,5,5,4,5},
{5,4,4,4,3,4,3,3,4},
{4,3,3,3,2,3,2,3,3},
};
}
}
一般的な戦略は、目標を達成するのに役立つデータ構造にデータを読み込むことです。あなたがnakano531の答えを見ると、コードが大部分を占めていることが分かります。 "Par Scores Chart"はファイルから読み込まれるのではなく、ハードコードされていますが、値は後で年齢によって引き出すことが容易なように、Map構造に配置されています。同様に、演習ファイルからのデータはプレイヤーオブジェクトのリストに読み込まれ、後でアクセスして使いやすくなります。そして、両方の構造体は 'main'メソッドでアクセスされます。 –