나는 퀴즈, 연구소, 실험실 출석, this- 퀴즈 추천하기 추천 중간 고사 표시 할 원하는 : 66 % 연구소 : 88 % 연구소 출석 : 81 % 중간 고사 : 해당 없음 전체 평균 : 최종 91 % 85 %. 하지만지고있어내 메서드에 적합한 출력을 얻으려면 어떻게해야합니까?
출력 : 내가 달성하기 위해 노력하고있어 적합한 출력을 얻을 것이다 어떻게
66.0
88.0
81.0
91.0
.
import java.io.*;
import java.util.*;
public class FindGrade {
public static final int NUM_SCORE_TYPES = 5;
public static void main(String[] args) {
Scanner scan = null;
int[] quizArray = null;
int[] labArray = null;
int[] attendance = null;
int[] midterms = null;
int quizgrade = 0;
int labgrade = 0;
int attendance_1 = 0;
int midterms_1 = 0;
String name;
try {
scan = new Scanner(new File("input.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
// each iteration is for single exam type (ie: Quizzes is the 1st one)
for (int i = 0; i < NUM_SCORE_TYPES; i++) {
name = scan.next();
int numScores = scan.nextInt();
int maxGrade = scan.nextInt();
if (name.equals("Quizzes")) {
quizArray = new int[numScores];
readScores(quizArray, numScores, scan,maxGrade);
} else if (name.equals("Labs")) {
labArray = new int[numScores];
readScores(labArray, numScores, scan,maxGrade);
} else if (name.equals("Lab_attendance")) {
attendance = new int[numScores];
readScores(attendance, numScores, scan,maxGrade);
} else if (name.equals("Midterms")) {
midterms = new int[numScores];
readScores(midterms, numScores, scan,maxGrade);
}
}
}
public static void readScores(int[] scoreArray, int numScores, Scanner scan, int maxGrade) {
for (int i = 0; i < numScores; i++) {
scoreArray[i] = scan.nextInt();
}
System.out.println(average(scoreArray, numScores, maxGrade));
}
public static int normalize(int[] scoreArray, int maxGrade) {
int total = 0;
for (int i = 0; i < scoreArray.length; i++) {
total += scoreArray[i];
}
int percent = Math.round(total * 100/maxGrade);
return percent;
}
public static double average(double[] scoreArray, int numScores,int maxGrade) {
double sum = 0;
for (int i = 0; i < scoreArray.length; i++) {
sum += scoreArray[i];
}
double average = Math.round((sum/numScores)*100/maxGrade);
return average;
}
입력 파일 :
Quizzes 8 10
5 8 9 10 4 0 10 7
Labs 6 100
95 90 100 87 63 92
Lab_attendance 16 1
1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1
Midterms 2 100
87 94
Final 0 100
전반적인 평균을 포함시키려는 경우 평균 방법과 동일한 방식으로 접근하겠습니까 – user124557
@ user124557 - 결과의 최종 평균을 취하는 것을 의미합니다. 예, 현명한 방법으로 사용 방법을 사용하거나 최종 평균 및 인쇄 계산을위한 별도의 방법. 희망이 도움이! – VibrantVivek
@ user124557님께 고맙습니다. 답변을 수락하시면 감사하겠습니다. 감사합니다. – VibrantVivek