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.










share|improve this question






















  • 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















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.










share|improve this question






















  • 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













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












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));
}
}





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    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

























    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));
    }
    }





    share|improve this answer

























      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));
      }
      }





      share|improve this answer























        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));
        }
        }





        share|improve this answer












        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));
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 16:47









        Johnny Mopp

        6,73722344




        6,73722344






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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