私の教授が以下のようなプログラムをやりたいと思う瞬間、私はそれを達成するのが難しいです。私はプッシュするのを助けるために助けを求めています。ここに指示と私がこれまで持っているものがあります。クリシズムとアドバイスが受け入れられました!Javaプログラムto
1)最高得点と生徒名
2)最小スコアと生徒名
3)クラス
4の平均スコア)生徒名とその項目を表示マーク付きのスコアの高い順に表示されます。スコアが平均以上の場合は、「+」記号付きの マークです。彼らの得点が平均に等しい場合は、 '='で印を付ける。それ以外の場合は、 ' - 'でマークします。私は何をすべきかの
例イメージ: https://i.gyazo.com/403819a89bae613452dd8278b0612d81.png
私の問題で、私は最高のスコアを取得するための配列をソートし、それに行く対応する名前でそれをプリントアウトする方法がわかりません。 私はまた、1.名前のような数字を入れる方法も知らない。2.最初に0で始まるので名前。
私の仕事:
public static void main(String[] args) {
System.out.println("********** Students and Scores ************");
Scanner input = new Scanner(System.in);
System.out.print("How many students in your class?: ");
int numStudents = input.nextInt();
double[] scores = new double[numStudents];
String[] students = new String[numStudents];
for (int i = 0; i < numStudents; i++) {
System.out.print(i + ". Name: ");
students[i] = input.next();
System.out.print("Score: ");
scores[i] = input.nextDouble();
}
double sum = 0;
for(int i=0; i < scores.length ; i++)
sum = sum + scores[i];
double average = sum/scores.length;
System.out.println("*************** Results *****************");
System.out.println("Average: " + average);
System.out.println("******* End of Students and Scores *********");
}
クラスを使用しよう! –
ここで読んでください(http://stackoverflow.com/questions/5245093/using-comparator-to-make-custom-sort)。 'name'と' score'を格納する 'Student'クラスを作ることを強く勧めます。そうすれば、2つの異なるリストで順序を維持する必要はありません。 –