943,585 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1204
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 1st, 2009
0

Re: Student Assignment

I had said before you don't need floats (or doubles) until you are FINALLY done and calculating the final GPA.

But you keep using it in the step by step calcuations so fine!

Java Syntax (Toggle Plain Text)
  1.  
  2. public double getGrade( GradeType myGrade )
  3. {
  4. return 4.0 - myGrade; // { 4...0} <--- {0...4}
  5. }

Note That I have a return to return the value passed into the function! You don't.
Also you have that dangling brace before the return! It's in the wrong place!

I also pass a 'GradeType' enum into the function for processing.
Last edited by wildgoose; Jul 1st, 2009 at 7:49 pm. Reason: tags
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Jul 1st, 2009
0

Re: Student Assignment

ok so now the error is this:

C:\Users\Ash Ketchum\Documents\New Folder\Student.java:39: class, interface, or enum expected
}
^
1 error

Tool completed with exit code 1
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lovley is offline Offline
8 posts
since Jul 2009
Jul 1st, 2009
0

Re: Student Assignment

count your braces!
For every { there is a }.
Print your code off. Write a little number next to each one! Add 1 for each { and -1 for each }
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Jul 2nd, 2009
0

Re: Student Assignment

I totally had a bracket at the very very bottom of the page lol....
anyways ok moving on.... so now I have to code the subclasses
since this method is already calculating the average do I just need to call it in the BachelorStudent?
And how would I go about adding the * 0.98 in the MasterStudent?
And yes I am sorry I feel extra lost if I don't put in the floaters and have the time I forget to put them back in and in the correct way but if it really bothers you I can try to leave them out........
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lovley is offline Offline
8 posts
since Jul 2009
Jul 2nd, 2009
0

Re: Student Assignment

You're only retrieving the converted grade. You need to sum the value with result in a bucket, and increment the grade item tally. When done then do your division.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Jul 2nd, 2009
0

Re: Student Assignment

ok so basically you're saying now I need to do the calculateGPA() method right..... I hope so because that's what I did next so for that I did this

JAVA Syntax (Toggle Plain Text)
  1. public double calculateGPA(double effectiveGPA)
  2. {
  3.  
  4. double grade = 0;
  5.  
  6. for (int i = 0; i<gradeList.size(); i++)
  7.  
  8. {
  9.  
  10. grade+= gradeList.get(i);
  11.  
  12. }
  13.  
  14. return grade/gradeList.size();
  15.  
  16. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lovley is offline Offline
8 posts
since Jul 2009
Jul 2nd, 2009
0

Re: Student Assignment

Click to Expand / Collapse  Quote originally posted by lovley ...
ok so basically you're saying now I need to do the calculateGPA() method right..... I hope so because that's what I did next so for that I did this

JAVA Syntax (Toggle Plain Text)
  1. public double calculateGPA(double effectiveGPA)
  2. {
  3.  
  4. double grade = 0;
  5.  
  6. for (int i = 0; i<gradeList.size(); i++)
  7.  
  8. {
  9.  
  10. grade+= gradeList.get(i);
  11.  
  12. }
  13.  
  14. return grade/gradeList.size();
  15.  
  16. }

This function is the same as this:

JAVA Syntax (Toggle Plain Text)
  1. public double calculateGPA()
  2. {
  3.  
  4. double grade = 0;
  5.  
  6. for (int i = 0; i<gradeList.size(); i++)
  7.  
  8. {
  9.  
  10. grade+= gradeList.get(i);
  11.  
  12. }
  13.  
  14. return grade/gradeList.size();
  15.  
  16. }

You pass the variable effectiveGPA , but don't use it, so you might as well not pass it.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Jul 2nd, 2009
0

Re: Student Assignment

Ohh... since my assignment said that the method calculateGPA() should returns a double and store it in the effectiveGPA variable I thought that is why I was doing that....
so would I put that in the () in the return line?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lovley is offline Offline
8 posts
since Jul 2009
Jul 2nd, 2009
0

Re: Student Assignment

effectiveGPA is a class/global variable. Don't pass it to a function. Copy and paste the ENTIRE program and post it here. Be extra careful to copy the entire thing, including all brackets, and mention all compiling errors.

Read the spec carefully:

Quote ...
Student has two child classes BachelorStudent and MasterStudent. Both classes should have the attribute effectiveGPA:double as well as the method calculateGPA() that returns a double and stores it in the effectiveGPA variable.
For the bachelor class, the method should take all the grades in the gradeList arraylist and average them out (Standard grades, A=4, B=3, C=2, D=1, F=0). For the masters class, the method does the same and then multiplies the result by 0.98.
calculateGPA () takes no arguments. It returns a double. It stores its result in effectiveGPA. You should therefore not have a variable called grade in your function. It should be effectiveGPA .

This should all be in the CHILD classes BachelorStudent and MasterStudent, not the parent class Student. Just make a dummy function in Student.

Java Syntax (Toggle Plain Text)
  1. public double calculateGPA ()
  2. {
  3. effectiveGPA = 0.0;
  4. return effectiveGPA;
  5. }

This function will NEVER be executed, but it still should be there in Student. The functions that will be executed will be in MasterStudent and BachelorStudent, which extend Student. If you haven't created MasterStudent and BachelorStudent yet, do so. You should also write some simple constructors now, as well as a very simple driver program.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Big errors i got plz help me out illegal type of expression type,
Next Thread in Java Forum Timeline: What is the Use of Inner classes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC