Trouble with output.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Steel546
    New Member
    • Mar 2009
    • 25

    Trouble with output.

    This program is used to calculate GPA. I'm having trouble actually getting an output. Alright, I KNOW that I don't have an output statement, but I don't know where to put it... heh. Netbeans keeps telling me it's wrong. So, here's my two classes.

    Code:
    package KyleTaylorGPA;
    
    public class GPA {
    
        private double theGPA;
        private int gradePointsSum;
        private int numHours;
    
        public GPA(double theGPA, int gradePointsSum, int numHours){
    
            theGPA = 0;
            gradePointsSum = 0;
            numHours = 0;
    
    
        }
        public double returnGPA() {
    
        theGPA = (double) gradePointsSum/ (double) numHours;
        return theGPA;
        }
    
        public void addCourse(int letterGrade, int currentNumHours) {
    
            // A would be represented by 1
            // B would be represented by 2
            // C would be represented by 3
            // D would be represented by 4
            // F would be represented by 5
    
            switch (letterGrade) {
                case 1:  gradePointsSum = gradePointsSum + 4 ; break;
                case 2:  gradePointsSum = gradePointsSum + 3 ; break;
                case 3:  gradePointsSum = gradePointsSum + 2 ; break;
                case 4:  gradePointsSum = gradePointsSum + 1 ; break;
                case 5:  gradePointsSum = gradePointsSum + 0 ; break;
           
            }
    
            numHours = numHours + currentNumHours;
    
        }
    
       public void addCourse(double transferGPA, int numTransferHours) {
    
        double x = 0;
        x = transferGPA * (double) numTransferHours;
    
        gradePointsSum = gradePointsSum + (int) x;
        numHours = numHours + numTransferHours;
    
        }
    
       public void addCourse(int currentNumHours, double percentageGrade) {
    
    int percentage;
    percentage = (int) percentageGrade;
    
    switch (percentage/10) {
                case 10: gradePointsSum = gradePointsSum + 4;
                case 9: gradePointsSum = gradePointsSum + 4;
                break;
                case 8: gradePointsSum = gradePointsSum + 3;
                break;
                case 7: gradePointsSum = gradePointsSum + 2;
                break;
                case 6: gradePointsSum = gradePointsSum + 1;
                break;
                case 5: gradePointsSum = gradePointsSum + 0;
                break;
                case 4: gradePointsSum = gradePointsSum + 0;
                break;
                case 3: gradePointsSum = gradePointsSum + 0;
                break;
                case 2: gradePointsSum = gradePointsSum + 0;
                break;
                case 1: gradePointsSum = gradePointsSum + 0;
                break;
        	}
    
    numHours = numHours + currentNumHours;
    
        }
    }
    Code:
    package KyleTaylorGPA;
    
    public class KyleTaylorGPA {
    
         public static void main(String[] args) {
    
             GPA calcGPA = new GPA(0,0,0);
             calcGPA.addCourse(1, 4);
             calcGPA.addCourse(2, 4);
             calcGPA.addCourse(3.5, 12);
             calcGPA.addCourse(3.2, 9);
             calcGPA.addCourse(4, 95);
             calcGPA.addCourse(6, 89);
             calcGPA.returnGPA();
    
         }
    }

    Any ideas? It's supposed to run with my returnGPA() statement.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    1.) What error message do you get?
    2.) Don't use Netbeans (or any IDE) if you are still learning Java.
    3.) See the "Read this first" thread at the top of these forums. It has links to tutorials that you must read.

    Comment

    • Steel546
      New Member
      • Mar 2009
      • 25

      #3
      It's alright. I got it. I actually had some problems with my switch statement, but I just couldn't get returnGPA to print, but then I fixed it. Thanks again though.

      Oh, and our school requires us to use Netbeans or Eclipse.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Steel546
        ...

        Oh, and our school requires us to use Netbeans or Eclipse.
        But you are still learning Java and IDEs make you get the work done without knowing how to do the work. Use the IDE at school then and use a plain text editor at home when you are really learning Java?

        P.S What do they do to you if you insist on using notepad (or textpad) until you have leaned all the basics properly?

        Comment

        • Steel546
          New Member
          • Mar 2009
          • 25

          #5
          Hm. I don't think they would actually do anything. There is a webCompiler on the CSE website, as if you were looking at notepad or somthing, then you can run it and see if it works.

          I think it's because they want a high rate of passing for students, since not everyone in Computer Science will be programming/software engineering, etc. (I would actually be one of those people).

          Comment

          • Jasonrodrigues
            New Member
            • Jul 2010
            • 3

            #6
            Originally posted by Steel546
            It's alright. I got it. I actually had some problems with my switch statement, but I just couldn't get returnGPA to print, but then I fixed it. Thanks again though.

            Oh, and our school requires us to use Netbeans or Eclipse.
            I also have same problem but I didnt get whats the problem when I run the program -- nothing comes up. Can you tell me whats wrong with swtich or any coding?
            thanks

            Comment

            • Steel546
              New Member
              • Mar 2009
              • 25

              #7
              Originally posted by Jasonrodrigues
              I also have same problem but I didnt get whats the problem when I run the program -- nothing comes up. Can you tell me whats wrong with swtich or any coding?
              thanks
              Wow this was old.

              Just post the code you have and we can see what's going on.

              Comment

              • Jasonrodrigues
                New Member
                • Jul 2010
                • 3

                #8
                Originally posted by Steel546
                Wow this was old.

                Just post the code you have and we can see what's going on.
                its the same code as posted above about GPA. My vlaues are different but it doesn't matter. So I also have same code as above

                Thanks for reply!!!

                Comment

                • TheServant
                  Recognized Expert Top Contributor
                  • Feb 2008
                  • 1168

                  #9
                  Is this homework?

                  Comment

                  • Jasonrodrigues
                    New Member
                    • Jul 2010
                    • 3

                    #10
                    Originally posted by TheServant
                    Is this homework?
                    No!!! I just confuse there.

                    Comment

                    Working...