aspose file tools*
The moose likes Beginning Java and the fly likes Averaging Grades Assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Averaging Grades Assignment" Watch "Averaging Grades Assignment" New topic
Author

Averaging Grades Assignment

Brandon Armstrong
Greenhorn

Joined: Dec 08, 2011
Posts: 4
Hello,

I also have this same assignment to do, and I'm stuck. this is what I have currently --

I was following the above code to get some idea's on how to do it, but then I got confused.



If someone can help me out and let me know where my error is that would be great!


Thanks in advance!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
Welcome to the Ranch

I shall split your question from this thread, because your question deserves a discussion to itself.

Yes, you are stuck. Where on earth did you get that BasketBall method from?
You are getting stuck because you are doing too much all at once. Is that BasketBall thing supposed to be a constructor? If so, it must not have a return type, and its name must be exactly the same as the class. I would suggest you comment out the method completely, and leave it out until you are sure the constructor will work. You will have to comment out the 5 calculate() calls in the main() method, too

That constructor won’t work, by the way. I shall give you a little time to work out why, before letting you out of yoru misery.

For commenting out, read on:
Brandon Armstrong
Greenhorn

Joined: Dec 08, 2011
Posts: 4
Tanks for the reply.

I made some changes to the code, from what I can see, everything should be working correctly...? --



But now i'm getting the two following errors --

Grades.java:26: illegal start of expression
void Grades()
^
Grades.java:26: ';' expected
void Grades()
^
2 errors

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

Where does your Grades constructor end? You're missing some brackets. But once you fix that, it'll just reveal some further problems...

Your finalMark declaration needs some work as well. It should be declared outside the constructor, but initialised inside it.

Your method on line 26 - is that meant to be another constructor (it isn't) or a method (in which case it's a bad choice of name)? And why do you define is as not having a return value and then return a value?

Also - check lines 16 to 19. You're assigning variables to themselves. You need to tell the compiler which are supposed to be the constructor arguments and which are instance variables. The compiler won't guess.

I'd suggest not trying to do so much at once. Start the class simple. Add a bit, and get it to compile and work. Otherwise you can get lost like this.


Brandon Armstrong
Greenhorn

Joined: Dec 08, 2011
Posts: 4
Okay, did some changes again, It now will compile and run, but will only give me this as a return --

null has a Quiz score of 0.0, and a Midterm mark of 0.0, A final Exam mark of 0.0, for a final grade of 0.0
null has a Quiz score of 0.0, and a Midterm mark of 0.0, A final Exam mark of 0.0, for a final grade of 0.0
null has a Quiz score of 0.0, and a Midterm mark of 0.0, A final Exam mark of 0.0, for a final grade of 0.0
null has a Quiz score of 0.0, and a Midterm mark of 0.0, A final Exam mark of 0.0, for a final grade of 0.0
null has a Quiz score of 0.0, and a Midterm mark of 0.0, A final Exam mark of 0.0, for a final grade of 0.0


Here is the code that I changed....

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

In that case, may I refer you the fourth paragraph of my previous answer .
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
I have already said that constructor would’t work

Those lines in the Grades method are too long, and I have had to insert new lines to make them legible. Don’t use tabs for indentation. That Grades() method doesn’t do what it says it does. It is doing several things, whereas a method ought to do one thing, despite what the original question said, and its name should reflect that. Grades() (apart from the capital G which is wrong) is not a helpful method name, and is close enough to the class name to cause confusion.
You ought to read the conditions in your if blocks very very carefully.
You ought to end a series of else if blocks with a plain else, and make sure that the blocks are arranged in the correct order. If the 1st block isn’t appropriate, the 2nd block should be tested and then control passes to the 3rd block if the test was false, etc., etc. The final block should be an else, which covers all cases which preceding blocks haven’t caught.

MB is right. You should be doing little bits and getting them working, rather than trying to change lots of code in the hope something will work.
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
In addition to the excellent advice already offered, I suggest: Break your code down into smaller, more focused tasks. The code that calculates the final mark should be separated from the code that assigns the letter grade. The code with the calls to system.out could all be consolidated into a single method that took as parameters the values that vary. These are all different tasks which will be more manageable if they are kept distinct.
Brandon Armstrong
Greenhorn

Joined: Dec 08, 2011
Posts: 4
Finished it....


 
 
subject: Averaging Grades Assignment