a print statement? what is it you are having trouble with?
also: since you compare instances of Grade, you may want to choose compareTo instead of the < operator.
stultuske
Industrious Poster
4,379 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
The Java compiler is your friend. Don't be afraid to try and compile your code. There's no point trying to get it right before compiling. Just chuck it into the compiler and see what errors it throws up. That costs you nothing.
At first you;ll get a lot of errors, but start with the first, fix them one at a time, re-compiling after each one.
But first...
Go back to your very first Java program (Hello World?). Remenber the method called main? Every program needs one. That's where you can: create new grades list, add some data to it, call your getLowest method, and print the result.
Have a look at that, if/when you get stuck come back here and post the whole of your code - it's hard to help you if we have to guess what's in the bits you didn't post!
JamesCherrill
... trying to help
8,525 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
I understand why you don't want to post all your code, but there is some more info neded. In particular, what is the return type for the getGrade() method? The name implies that it returns a Grade object (in which case you need to get compareTo working), but the context suggests that it's unlikely to be a Grade object. If, for example, it just returns an int or a char then you can compare with a simple <
(s.getGrade.compareTo(lowestGrade.getGrade)
Unless getGrade is also a variable this syntax is wrong. If, as the name suggests, it's a method then you need a (...) for the parameter list, even if it's empty ... eg s.getGrade()
JamesCherrill
... trying to help
8,525 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
So far you posted getGrade (no parameter list) and getGrade() (empty parameter list), yet the method signature requires a parameter of type Score, so neither of those is right. And what's the difference between a Score and a Grade? Line 6 implies that a Score can be equal to a Grade, but without the class definitions who knows?
Grade NOTFOUND = grades.get(-1); will never assign a value to NOTFOUND, and none of the rest of findGrade will ever be executed because it will always throw an exception first (see the JavaDoc for ArrayList's get(int) method). Similarly getGrade will also stop executing and throw the exception as soon as it calls findGrade. (And why call findGrade anyway when you just ignore the value it returns). From which I guess you haven't been able to execute any of this code yet.
It seems to me that you are trying to code this in pieces that are too big. You will have fewer problems if you write one method at a time, write some trivial discardable code to test that method, and get the method working before starting on the next method. If you try to write too much in one go then you get buried in errors when you finally try to compuile and run, and its really hard to see where to start fixing things.
JamesCherrill
... trying to help
8,525 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
In that case, it's time to stop and read the instructions properly:
Instruction: NOTFOUND is set to -1;
Your code: NOTFOUND = grades.get(-1);
Instruction: findGrade - private method given a parameter representing the grade's date
Your code: findGrade(Grade aGrade)
Instruction: returns the ArrayList index of a grade
Your code: Grade g .... return g;
So that's three examples of not following the instructions just from that tiny excerpt.
For your own sake I would start again with a clean sheet of paper and re-read the instructions until you understand every single word in them. Until then your code is doomed to go off in random directions.
Please don't think I'm being negative or critical; I'm just giving the best advice I can, even if it's uncomfortable.
JamesCherrill
... trying to help
8,525 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
OK. Don't worry. Keep posting your problems and we will try to help.
JamesCherrill
... trying to help
8,525 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
Excellent! Glad we could help.
Perhaps you can mark this thread "solved" now. If you run into problems with your next assignment you can start a new thread.
J
JamesCherrill
... trying to help
8,525 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
Question Answered as of 2 Months Ago by
JamesCherrill
and
stultuske