By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,787 Members | 2,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,787 IT Pros & Developers. It's quick & easy.

Trouble with output.

Steel546
P: 25
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. package KyleTaylorGPA;
  3.  
  4. public class GPA {
  5.  
  6.     private double theGPA;
  7.     private int gradePointsSum;
  8.     private int numHours;
  9.  
  10.     public GPA(double theGPA, int gradePointsSum, int numHours){
  11.  
  12.         theGPA = 0;
  13.         gradePointsSum = 0;
  14.         numHours = 0;
  15.  
  16.  
  17.     }
  18.     public double returnGPA() {
  19.  
  20.     theGPA = (double) gradePointsSum/ (double) numHours;
  21.     return theGPA;
  22.     }
  23.  
  24.     public void addCourse(int letterGrade, int currentNumHours) {
  25.  
  26.         // A would be represented by 1
  27.         // B would be represented by 2
  28.         // C would be represented by 3
  29.         // D would be represented by 4
  30.         // F would be represented by 5
  31.  
  32.         switch (letterGrade) {
  33.             case 1:  gradePointsSum = gradePointsSum + 4 ; break;
  34.             case 2:  gradePointsSum = gradePointsSum + 3 ; break;
  35.             case 3:  gradePointsSum = gradePointsSum + 2 ; break;
  36.             case 4:  gradePointsSum = gradePointsSum + 1 ; break;
  37.             case 5:  gradePointsSum = gradePointsSum + 0 ; break;
  38.  
  39.         }
  40.  
  41.         numHours = numHours + currentNumHours;
  42.  
  43.     }
  44.  
  45.    public void addCourse(double transferGPA, int numTransferHours) {
  46.  
  47.     double x = 0;
  48.     x = transferGPA * (double) numTransferHours;
  49.  
  50.     gradePointsSum = gradePointsSum + (int) x;
  51.     numHours = numHours + numTransferHours;
  52.  
  53.     }
  54.  
  55.    public void addCourse(int currentNumHours, double percentageGrade) {
  56.  
  57. int percentage;
  58. percentage = (int) percentageGrade;
  59.  
  60. switch (percentage/10) {
  61.             case 10: gradePointsSum = gradePointsSum + 4;
  62.             case 9: gradePointsSum = gradePointsSum + 4;
  63.             break;
  64.             case 8: gradePointsSum = gradePointsSum + 3;
  65.             break;
  66.             case 7: gradePointsSum = gradePointsSum + 2;
  67.             break;
  68.             case 6: gradePointsSum = gradePointsSum + 1;
  69.             break;
  70.             case 5: gradePointsSum = gradePointsSum + 0;
  71.             break;
  72.             case 4: gradePointsSum = gradePointsSum + 0;
  73.             break;
  74.             case 3: gradePointsSum = gradePointsSum + 0;
  75.             break;
  76.             case 2: gradePointsSum = gradePointsSum + 0;
  77.             break;
  78.             case 1: gradePointsSum = gradePointsSum + 0;
  79.             break;
  80.         }
  81.  
  82. numHours = numHours + currentNumHours;
  83.  
  84.     }
  85. }
  86.  
Expand|Select|Wrap|Line Numbers
  1. package KyleTaylorGPA;
  2.  
  3. public class KyleTaylorGPA {
  4.  
  5.      public static void main(String[] args) {
  6.  
  7.          GPA calcGPA = new GPA(0,0,0);
  8.          calcGPA.addCourse(1, 4);
  9.          calcGPA.addCourse(2, 4);
  10.          calcGPA.addCourse(3.5, 12);
  11.          calcGPA.addCourse(3.2, 9);
  12.          calcGPA.addCourse(4, 95);
  13.          calcGPA.addCourse(6, 89);
  14.          calcGPA.returnGPA();
  15.  
  16.      }
  17. }
  18.  

Any ideas? It's supposed to run with my returnGPA() statement.
Mar 31 '09 #1
Share this Question
Share on Google+
9 Replies


10K+
P: 13,264
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.
Apr 1 '09 #2

Steel546
P: 25
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.
Apr 1 '09 #3

10K+
P: 13,264
@Steel546
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?
Apr 6 '09 #4

Steel546
P: 25
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).
Apr 6 '09 #5

P: 3
@Steel546
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
Jul 18 '10 #6

Steel546
P: 25
@Jasonrodrigues
Wow this was old.

Just post the code you have and we can see what's going on.
Jul 21 '10 #7

P: 3
@Steel546
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!!!
Jul 21 '10 #8

TheServant
Expert 100+
P: 1,168
Is this homework?
Jul 22 '10 #9

P: 3
@TheServant
No!!! I just confuse there.
Jul 22 '10 #10

Post your reply

Sign in to post your reply or Sign up for a free account.