题目要求如下:
代码如下:
import java.math.BigDecimal;
import java.util.Scanner;
/**
* Created with IntelliJ IDEA.
* Description:
* User: Y
* Date: 2019-07-29
* Time: 20:53
*/
public class Main1 {
private static double getGPA() {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
if (num == 0 || num >= 10) return -1;
int[] arr1 = new int[num];
int[] arr2 = new int[num];
double score = 0;
int credit = 0;
for (int i = 0; i < num; i++) {
arr1[i] = scanner.nextInt();
}
for (int i = 0; i < num; i++) {
arr2[i] = scanner.nextInt();
}
for (int i = 0; i < num; i++) {
int q = arr2[i];
credit += arr1[i];
if (q <= 100 && q >= 90) {
score += 4.0*arr1[i];
}
if (q <= 89 && q >= 85) {
score += 3.7*arr1[i];
}
if (q <= 84 && q >= 82) {
score += 3.3*arr1[i];
}
if (q <= 81 && q >= 78) {
score += 3.0*arr1[i];
}
if (q <= 77 && q >= 75) {
score += 2.7*arr1[i];
}
if (q <= 74 && q >= 72) {
score += 2.3*arr1[i];
}
if (q <= 71 && q >= 68) {
score += 2.0*arr1[i];
}
if (q <= 67 && q >= 64) {
score += 1.5*arr1[i];
}
if (q <= 63 && q >= 60) {
score += 1.0*arr1[i];
}
if (q < 60) {
score += 0;
}
}
double GPA = new BigDecimal( score / credit).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return GPA;
}
public static void main(String[] args) {
System.out.println(getGPA());
}
}