如何将数组传递给方法以将double转换为字符串？

问题描述投票：1回答：2

``````public static void main(String[] args) {

//TODO:
//declare an array to hold the grades you earned in your classes
//feel free to use fake values
//use a 0.0 - 4.0 scale...
//4.0 = A, 3.5 = A/B
//3.0 = B, 2.5 = B/C
//2.0 = C
//1.0 = D
//0.0 = F
//for example...

//TODO:
//use a method to print the min and max grades as letter grades

//TODO:
//declare an array to hold the credits each class was worth
//the indices must match the grade[i] indices for the class
//for example...
int[] credit = new int[4];
credit[0] = 3;
credit[1] = 3;
credit[2] = 3;
credit[3] = 3;

//TODO:
//use a method to calculate and print the GPA as both
//a number and a letter grade
//pass both the credit and grade arrays to the method
}

//TODO:
//Finish this method which will accept an array of grades
//and print the min and max letter grade

//TODO:
//First determine the min and max letter grade...

for(int i = 0; i < grade.length; i++) {
}
}
}
//TODO:
//For example...
//TODO:
//Output them...
}

//TODO:
//Finish this method which will convert
//Use the following scale...
//A = 4.0
//4.0 > A/B >= 3.5
//3.5 > B >= 3.0
//3.0 > B/C >= 2.5
//2.5 > C >= 2.0
//2.0 > D >= 1.0
//F < 1.0

}

//TODO:
//Finish this method which will accept an array of grades and credits
//and print the cumulative GPA as a letter grade
private static void printGPA(double[] grade, int[] credit){

//Recall...GPA is just a weighted average...
//Cumulative GPA is the sum of all grade points -- grade[i] * credit[i]
//divided by the sum of all credits[i]
double sumCredits = 0;
//TODO:
//Calculate cumulative GPA

for (int n = 0; n < credit.length; n++) {
sumCredits += credit[n];
}

//TODO:
//Output Cumulative GPA as both a number and a grade
System.out.println("Cumulative GPA " + gpa);
System.out.println("Cumulative GPA as a letter grade: ");
}
``````

}

java
2个回答
0

``````private static String convertToLetterGrade(double grade){
}
}
``````

0

``````double gpa = 0.0;
for (int n = 0; n < credit.length; n++) {
sumCredits += credit[n];
}

gpa /= sumCredits;
``````

Logic中的一件事，

``````    double minGrade = 5.0; // Or any max value, because you are going to find minimum values that this default one