Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: can anyone help?

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question can anyone help?

    So, this is a GPA Calculator. I want it to allow the user to enter the number of classes they have and use that number to determine how many times to ask them what the grade is.

    import java.io.*;
     
    import static java.lang.System.*;
     
    import java.util.Scanner;
     
     
     
     
     
     
     
    class GPACalculator{
     
     
     
     
     
      public static void main (String str[]) throws IOException{
     
     
     
        Scanner scan = new Scanner (System.in);
     
     
     
          double a;
     
          double b;
     
          double c;
     
          double d;
     
          double e;
     
          double f;
     
          double g;
     
          double h;
     
          double r;
     
     
     
        System.out.println("Please enter the number of classes you have.");
     
        r = scan.nextDouble();
     
        if (r == 1);{
     
          System.out.println("Please enter the number corresponding with your class grades.");
     
          System.out.println("A = 4, B = 3, C = 2, D = 1 and F = 0");
     
          System.out.println("Please enter 'Class 1'");
     
          a = scan.nextDouble();
     
          System.out.println("Your GPA is " + a + ".");}
     
          if(false)
     
            return;
     
     
     
        if (r == 2);{
     
          System.out.println("Please enter the number corresponding with your class grades.");
     
          System.out.println("A = 4, B = 3, C = 2, D = 1 and F = 0");
     
          System.out.println("Please enter 'Class 1'");
     
          a = scan.nextDouble();
     
          System.out.println("Please enter 'Class 2'");
     
          b = scan.nextDouble();
     
          double x = (double) (a + b)/2;
     
          System.out.println("Your GPA is " + x + ".");}
     
          if(false)
     
            return;
     
     
     
        if (r == 3);{
     
          System.out.println("Please enter the number corresponding with your class grades.");
     
          System.out.println("A = 4, B = 3, C = 2, D = 1 and F = 0");
     
          System.out.println("Please enter 'Class 1'");
     
          a = scan.nextDouble();
     
          System.out.println("Please enter 'Class 2'");
     
          b = scan.nextDouble();
     
          System.out.println("Please enter 'Class 3'");
     
          c = scan.nextDouble();
     
          double y = (double) (a + b + c)/3;
     
          System.out.println("Your GPA is " + y + ".");}
     
          if(false)
     
            return;
     
     
     
        if (r == 4);{
     
          System.out.println("Please enter the number corresponding with your class grades.");
     
          System.out.println("A = 4, B = 3, C = 2, D = 1 and F = 0");
     
          System.out.println("Please enter 'Class 1'");
     
          a = scan.nextDouble();
     
          System.out.println("Please enter 'Class 2'");
     
          b = scan.nextDouble();
     
          System.out.println("Please enter 'Class 3'");
     
          c = scan.nextDouble();
     
          System.out.println("Please enter 'Class 4'");
     
          d = scan.nextDouble();
     
          double z = (double) (a + b + c + d)/4;
     
          System.out.println("Your GPA is " + z + ".");}
     
          if(false)
     
            return;
     
     
     
        if (r == 5);{
     
          System.out.println("Please enter the number corresponding with your class grades.");
     
          System.out.println("A = 4, B = 3, C = 2, D = 1 and F = 0");
     
          System.out.println("Please enter 'Class 1'");
     
          a = scan.nextDouble();
     
          System.out.println("Please enter 'Class 2'");
     
          b = scan.nextDouble();
     
          System.out.println("Please enter 'Class 3'");
     
          c = scan.nextDouble();
     
          System.out.println("Please enter 'Class 4'");
     
          d = scan.nextDouble();
     
          System.out.println("Please enter 'Class 5'");
     
          e = scan.nextDouble();
     
          double w = (double) (a + b + c + d + e)/5;
     
          System.out.println("Your GPA is " + w + ".");}
     
          if(false)
     
            return;
     
     
     
        if (r == 6);{
     
          System.out.println("Please enter the number corresponding with your class grades.");
     
          System.out.println("A = 4, B = 3, C = 2, D = 1 and F = 0");
     
          System.out.println("Please enter 'Class 1'");
     
          a = scan.nextDouble();
     
          System.out.println("Please enter 'Class 2'");
     
          b = scan.nextDouble();
     
          System.out.println("Please enter 'Class 3'");
     
          c = scan.nextDouble();
     
          System.out.println("Please enter 'Class 4'");
     
          d = scan.nextDouble();
     
          System.out.println("Please enter 'Class 5'");
     
          e = scan.nextDouble();
     
          System.out.println("Please enter 'Class 6'");
     
          f = scan.nextDouble();
     
          double v = (double) (a + b + c + d + e + f)/6;
     
          System.out.println("Your GPA is " + v + ".");}
     
          if(false)
     
            return;
     
     
     
        if (r == 7);{
     
          System.out.println("Please enter the number corresponding with your class grades.");
     
          System.out.println("A = 4, B = 3, C = 2, D = 1 and F = 0");
     
          System.out.println("Please enter 'Class 1'");
     
          a = scan.nextDouble();
     
          System.out.println("Please enter 'Class 2'");
     
          b = scan.nextDouble();
     
          System.out.println("Please enter 'Class 3'");
     
          c = scan.nextDouble();
     
          System.out.println("Please enter 'Class 4'");
     
          d = scan.nextDouble();
     
          System.out.println("Please enter 'Class 5'");
     
          e = scan.nextDouble();
     
          System.out.println("Please enter 'Class 6'");
     
          f = scan.nextDouble();
     
          System.out.println("Please enter 'Class 7'");
     
          g = scan.nextDouble();
     
          double u = (double) (a + b + c + d + e + f + g)/7;
     
          System.out.println("Your GPA is " + u + ".");}
     
          if(false)
     
            return;
     
     
     
        if (r == 8);{
     
          System.out.println("Please enter the number corresponding with your class grades.");
     
          System.out.println("A = 4, B = 3, C = 2, D = 1 and F = 0");
     
          System.out.println("Please enter 'Class 1'");
     
          a = scan.nextDouble();
     
          System.out.println("Please enter 'Class 2'");
     
          b = scan.nextDouble();
     
          System.out.println("Please enter 'Class 3'");
     
          c = scan.nextDouble();
     
          System.out.println("Please enter 'Class 4'");
     
          d = scan.nextDouble();
     
          System.out.println("Please enter 'Class 5'");
     
          e = scan.nextDouble();
     
          System.out.println("Please enter 'Class 6'");
     
          f = scan.nextDouble();
     
          System.out.println("Please enter 'Class 7'");
     
          g = scan.nextDouble();
     
          System.out.println("Please enter 'Class 8'");
     
          h = scan.nextDouble();
     
          double t = (double) (a + b + c + d + e + f + g + h)/8;
     
          System.out.println("Your current GPA is " + t + ".");}
     
          if(false)
     
            return;
     
     
     
     
     
      }
     
    }

  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: can anyone help?

    And your question is?

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: can anyone help?

    I'm not sure how to do that.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: can anyone help?

    Why do you have variables names 'a' through 'r'? Give your variables meaningful names.

    Do you know for() loops? Do you know arrays?

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: can anyone help?

    Quote Originally Posted by GregBrannon View Post
    Why do you have variables names 'a' through 'r'? Give your variables meaningful names.

    Do you know for() loops? Do you know arrays?
    No, I'm new to Java coding.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,406
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: can anyone help?

    See the tutorial:
    The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
    If you don't understand my answer, don't ignore it, ask a question.