cre是当前累计的学分,因为当前学时为12,所以乘以12。
req是我达到目标CGPA的最低学分的等式。
cre = data[0][0]*12;
req = (26*data[0][1])-cre;
在下学期,将选修4门科目,每门科目的学时为4,4,3,3.total up =14。所以我得出了这一点,我想做的是创建一个循环并将x递增0.01,直到子的总学分达到要求:
if(((56+cre)/26)>data[0][1]) {
do {
double x = i/100;
sub1 = 4*x;
sub2 = 4*x;
sub3 = 3*x;
sub4 = 3*x;
total = sub1 + sub2 + sub3 + sub4;
i++;
} while (total<req);
System.out.println(sub1/4.0);
System.out.println(sub2/4.0);
System.out.println(sub3/3.0);
System.out.println(sub4/3.0);
}
最后,我尝试将所有子项分别除以4和3,以找到每个受试者达到目标CGPA所需的最低gpa。
答案 0 :(得分:0)
没有更多信息,我们只能猜测。很有可能是这个问题:
double x = i/100;
如果i
是整数,则每i
小于100等于零。您可能需要浮点除法。
double x = i/100.0;
您可以通过一些数学找到一个更简单的解决方案。首先,计算GPA的公式为
sum(grade_points_for_all_classes) / total_hours = GPA
任何课程的“成绩点”都是
grade * credit_hours
现在,我们要计算所有新班级的最低成绩(min_grade
),以达到新的desired_gpa
。等式应该是
(sum(grade_points_for_prev_classes) + (min_grade * sum(new_class_hours)) / total_hours = desired_gpa
total_hours
是总学时数(新旧班级)。解决min_grade
,我们得到:
min_grade = (desired_gpa * total_hours - sum(grade_points_for_prev_classes)) / sum(new_class_hours)
示例:
public static void main (String[] args) throws java.lang.Exception
{
double goalGPA = 3.25;
// Create an array of previous courses
double [][] prevCourses = {
{4, 4.0},
{4, 3.0},
{3, 2.0},
{2, 1.0}
};
// Calc grade points for prev courses
// and also total credit hours for prev courses
double gradePointsPrevCourses = 0;
int totalCreditHours = 0;
for (double [] c : prevCourses) {
gradePointsPrevCourses += c[0] * c[1];
totalCreditHours += c[0];
}
// Create an array of the new courses
// Not concerned with grades yet so fill with zero
double [][] newCourses = {
{4, 0.0},
{4, 0.0},
{3, 0.0},
{3, 0.0}
};
// Calc new credit hours
// and add to prev credit hours
int newCreditHours = 0;
for (double [] c : newCourses) {
newCreditHours += c[0];
}
totalCreditHours += newCreditHours;
// Solve
double minGrade = (goalGPA * totalCreditHours - gradePointsPrevCourses) / newCreditHours;
if (minGrade <= 4.0) {
System.out.println(String.format("You will need a %.2f in all classes to get a %.2f GPA", minGrade, goalGPA));
}
else {
System.out.println(String.format("Sorry, a %.2f is unobtainable.", goalGPA));
}
}