Ask for student's current CGPA and target CGPA, and then calculate minimum grade to achieve target CGPA
up vote
-2
down vote
favorite
cre is currently accumulated credits, multiply by 12 because current credit hours is 12.
req is my equation of minimum credits to hit target CGPA.
cre = data[0][0]*12;
req = (26*data[0][1])-cre;
For next semester, 4 subjects are taken, and the credits hour for each subject is 4,4,3,3.Total up = 14. So I come out with this, what am I trying to do is create a loop and increment x by 0.01 until the total credits of subs meet the req:
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);
}
Lastly, I try to divide all subs by 4 and 3 to find minimum gpa required for each subjects to hit the target CGPA.
java loops
add a comment |
up vote
-2
down vote
favorite
cre is currently accumulated credits, multiply by 12 because current credit hours is 12.
req is my equation of minimum credits to hit target CGPA.
cre = data[0][0]*12;
req = (26*data[0][1])-cre;
For next semester, 4 subjects are taken, and the credits hour for each subject is 4,4,3,3.Total up = 14. So I come out with this, what am I trying to do is create a loop and increment x by 0.01 until the total credits of subs meet the req:
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);
}
Lastly, I try to divide all subs by 4 and 3 to find minimum gpa required for each subjects to hit the target CGPA.
java loops
I don't think my code is correct, cause I am having all equal output. For eg, 3.5 3.5 3.5 3.5. It is supposed to be 3.5 3.5 3.0 2.0, something like this
– Michael
Nov 19 at 13:28
Please amend your question accordingly so that the problem is well-described, but in the shortes possible manner.
– planetmaker
Nov 19 at 14:32
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
cre is currently accumulated credits, multiply by 12 because current credit hours is 12.
req is my equation of minimum credits to hit target CGPA.
cre = data[0][0]*12;
req = (26*data[0][1])-cre;
For next semester, 4 subjects are taken, and the credits hour for each subject is 4,4,3,3.Total up = 14. So I come out with this, what am I trying to do is create a loop and increment x by 0.01 until the total credits of subs meet the req:
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);
}
Lastly, I try to divide all subs by 4 and 3 to find minimum gpa required for each subjects to hit the target CGPA.
java loops
cre is currently accumulated credits, multiply by 12 because current credit hours is 12.
req is my equation of minimum credits to hit target CGPA.
cre = data[0][0]*12;
req = (26*data[0][1])-cre;
For next semester, 4 subjects are taken, and the credits hour for each subject is 4,4,3,3.Total up = 14. So I come out with this, what am I trying to do is create a loop and increment x by 0.01 until the total credits of subs meet the req:
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);
}
Lastly, I try to divide all subs by 4 and 3 to find minimum gpa required for each subjects to hit the target CGPA.
java loops
java loops
asked Nov 19 at 13:11
Michael
21
21
I don't think my code is correct, cause I am having all equal output. For eg, 3.5 3.5 3.5 3.5. It is supposed to be 3.5 3.5 3.0 2.0, something like this
– Michael
Nov 19 at 13:28
Please amend your question accordingly so that the problem is well-described, but in the shortes possible manner.
– planetmaker
Nov 19 at 14:32
add a comment |
I don't think my code is correct, cause I am having all equal output. For eg, 3.5 3.5 3.5 3.5. It is supposed to be 3.5 3.5 3.0 2.0, something like this
– Michael
Nov 19 at 13:28
Please amend your question accordingly so that the problem is well-described, but in the shortes possible manner.
– planetmaker
Nov 19 at 14:32
I don't think my code is correct, cause I am having all equal output. For eg, 3.5 3.5 3.5 3.5. It is supposed to be 3.5 3.5 3.0 2.0, something like this
– Michael
Nov 19 at 13:28
I don't think my code is correct, cause I am having all equal output. For eg, 3.5 3.5 3.5 3.5. It is supposed to be 3.5 3.5 3.0 2.0, something like this
– Michael
Nov 19 at 13:28
Please amend your question accordingly so that the problem is well-described, but in the shortes possible manner.
– planetmaker
Nov 19 at 14:32
Please amend your question accordingly so that the problem is well-described, but in the shortes possible manner.
– planetmaker
Nov 19 at 14:32
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Without more information, we can only guess. Most likely this is the issue:
double x = i/100;
If i is an integer, then this will equal zero for every i less than 100. You probably want floating point division.
double x = i/100.0;
You could find a simpler solution with a little math. First, the equation for calculating GPA is
sum(grade_points_for_all_classes) / total_hours = GPA
The "grade point" for any class is
grade * credit_hours
Now, we want to calc the min grade (min_grade) for all the new classes to reach a new desired_gpa. The equation would be
(sum(grade_points_for_prev_classes) + (min_grade * sum(new_class_hours)) / total_hours = desired_gpa
Where total_hours is the total number of credit hours (new and old classes). Solving for min_grade we get:
min_grade = (desired_gpa * total_hours - sum(grade_points_for_prev_classes)) / sum(new_class_hours)
Example:
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));
}
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Without more information, we can only guess. Most likely this is the issue:
double x = i/100;
If i is an integer, then this will equal zero for every i less than 100. You probably want floating point division.
double x = i/100.0;
You could find a simpler solution with a little math. First, the equation for calculating GPA is
sum(grade_points_for_all_classes) / total_hours = GPA
The "grade point" for any class is
grade * credit_hours
Now, we want to calc the min grade (min_grade) for all the new classes to reach a new desired_gpa. The equation would be
(sum(grade_points_for_prev_classes) + (min_grade * sum(new_class_hours)) / total_hours = desired_gpa
Where total_hours is the total number of credit hours (new and old classes). Solving for min_grade we get:
min_grade = (desired_gpa * total_hours - sum(grade_points_for_prev_classes)) / sum(new_class_hours)
Example:
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));
}
}
add a comment |
up vote
0
down vote
Without more information, we can only guess. Most likely this is the issue:
double x = i/100;
If i is an integer, then this will equal zero for every i less than 100. You probably want floating point division.
double x = i/100.0;
You could find a simpler solution with a little math. First, the equation for calculating GPA is
sum(grade_points_for_all_classes) / total_hours = GPA
The "grade point" for any class is
grade * credit_hours
Now, we want to calc the min grade (min_grade) for all the new classes to reach a new desired_gpa. The equation would be
(sum(grade_points_for_prev_classes) + (min_grade * sum(new_class_hours)) / total_hours = desired_gpa
Where total_hours is the total number of credit hours (new and old classes). Solving for min_grade we get:
min_grade = (desired_gpa * total_hours - sum(grade_points_for_prev_classes)) / sum(new_class_hours)
Example:
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));
}
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Without more information, we can only guess. Most likely this is the issue:
double x = i/100;
If i is an integer, then this will equal zero for every i less than 100. You probably want floating point division.
double x = i/100.0;
You could find a simpler solution with a little math. First, the equation for calculating GPA is
sum(grade_points_for_all_classes) / total_hours = GPA
The "grade point" for any class is
grade * credit_hours
Now, we want to calc the min grade (min_grade) for all the new classes to reach a new desired_gpa. The equation would be
(sum(grade_points_for_prev_classes) + (min_grade * sum(new_class_hours)) / total_hours = desired_gpa
Where total_hours is the total number of credit hours (new and old classes). Solving for min_grade we get:
min_grade = (desired_gpa * total_hours - sum(grade_points_for_prev_classes)) / sum(new_class_hours)
Example:
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));
}
}
Without more information, we can only guess. Most likely this is the issue:
double x = i/100;
If i is an integer, then this will equal zero for every i less than 100. You probably want floating point division.
double x = i/100.0;
You could find a simpler solution with a little math. First, the equation for calculating GPA is
sum(grade_points_for_all_classes) / total_hours = GPA
The "grade point" for any class is
grade * credit_hours
Now, we want to calc the min grade (min_grade) for all the new classes to reach a new desired_gpa. The equation would be
(sum(grade_points_for_prev_classes) + (min_grade * sum(new_class_hours)) / total_hours = desired_gpa
Where total_hours is the total number of credit hours (new and old classes). Solving for min_grade we get:
min_grade = (desired_gpa * total_hours - sum(grade_points_for_prev_classes)) / sum(new_class_hours)
Example:
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));
}
}
answered Nov 19 at 16:47
Johnny Mopp
6,73722344
6,73722344
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375402%2fask-for-students-current-cgpa-and-target-cgpa-and-then-calculate-minimum-grade%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I don't think my code is correct, cause I am having all equal output. For eg, 3.5 3.5 3.5 3.5. It is supposed to be 3.5 3.5 3.0 2.0, something like this
– Michael
Nov 19 at 13:28
Please amend your question accordingly so that the problem is well-described, but in the shortes possible manner.
– planetmaker
Nov 19 at 14:32