Thread: Help calculate GPA

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    2

    Help calculate GPA

    Hi guy!
    I want clone follow website Semester Grade Calculator - EASY Use Semester Exam Grade Calculator
    Here's what I need to be able to output:

    Eligible
    Ineligible, taking less than 4 classes
    Ineligible, gpa below 2.0
    Ineligible, gpa above 2.0 but has F grade (note: gpa >= 2.0)
    Ineligible, gpa below 2.0 and has F grade
    It keeps asking for input. How do I stop this? I tried converting grade into a char but that ended horribly for me. I think it might be a compiler error or something. Any help would be appreciated. Though helpful help would keep my blood pressure down.
    here's my code so far:
    Code:
    import java.util.Scanner; 
    
    public class gpa {
    
    public static void main(String[] args) {
    double gpa=0;
    double input = 0;
    String grade= "";
    int classes =0;
    double fail =0;
    do
    {
    System.out.print("Enter Grade (n to quit): "); 
    Scanner sc = new Scanner(System.in); 
    grade = sc.nextLine(); 
    grade = grade.toLowerCase(); 
    if (grade.equals("a"))
    {
    input = 4.0;
    }
    if (grade.equals("b"))
    {
    input = 3.0;
    }
    if (grade.equals("c"))
    {
    input = 2.0;
    }
    if (grade.equals("d"))
    {
    input = 1.0;
    }
    if (grade.equals("f"))
    {
    fail = 1;
    }
    
    gpa+=input;
    classes++;
    } while(grade!="n");
    System.out.print("GPA: " + gpa + " "); 
    
    gpa/=classes;
    if (gpa>=2 && classes >=4 && fail !=1)
    {
    System.out.print("Eligible"); 
    }
    else if(classes <4)
    {
    System.out.print("Ineligible. less than 4 classes"); 
    }
    else if (gpa < 2.0)
    {
    System.out.print("Ineligible. GPA is less than 2.0"); 
    }
    else if (gpa >=2.0 && fail == 1)
    {
    System.out.print("Ineligible. GPA is above 2.0, but has an F");
    }
    else if (gpa <2.0 && fail ==1)
    {
    System.out.print("Ineligible. GPA is below 2.0 and has F");
    }
    }
    
    }
    

  2. #2
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    I am sorry, but you are in the wrong place. This thread is for C Programming not for Java.
    For Java problems you can try Programming and Web Development Help | DreamInCode.net

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > I think it might be a compiler error or something.
    It's far more likely to be a PICNIC problem IMO.

    Like for example, knowing how to use google to "find" code, but not actually knowing any Java to actually fix simple problems.
    Java GPA calculator/take all grade strings in order to create final gpa/Scanner/String - Stack Overflow
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to calculate GPA
    By avavida in forum General Discussions
    Replies: 1
    Last Post: 05-21-2017, 12:33 PM
  2. Calculate E
    By hyper nova in forum C Programming
    Replies: 4
    Last Post: 03-10-2016, 07:25 AM
  3. calculate 100! bug.
    By nimitzhunter in forum C++ Programming
    Replies: 11
    Last Post: 03-29-2014, 11:50 PM
  4. Calculate BMI and BMR
    By nguystep in forum C Programming
    Replies: 4
    Last Post: 10-26-2011, 02:59 AM
  5. Suggestions on how to calculate something
    By Bnchs in forum C++ Programming
    Replies: 3
    Last Post: 11-09-2007, 06:14 AM

Tags for this Thread