Hey guys, im pretty new to java as this is my first time ever taking such a course, and i have an assignment that i have to complete that im stuck on and i have no idea what to do next.
Heres what i have so far, and i doubt its right
Now, what i have to do is create a method getLetterGrade, which i think i have done correctly, and i also have to have it so it outputs the class average, the class minimum, and the class maximum as letter grades. So im stuck because i have to make it ask the user how many grades there putting in and such to get the average, min, and max, but i first have to figure out how i could get the average which is where im stuck. Hopefully you guys can help., and if you dont understand really what im asking, i can just put the actual question in for you.
J Rock wrote:
So im stuck because i have to make it ask the user how many grades there putting in and such to get the average, min, and max, but i first have to figure out how i could get the average which is where im stuck.
Well, it depends on where the data is stored (after you asked the user for the data). The average is a straightforward mathematical calculation. It is merely, the sum of the numbers divided by how many numbers.
Your method looks good. As far as entering grades, why do you have to know how many grades the user is entering before you start? What if you kept track yourself? You can keep a variable to count how many grades have been entered so far. Think about the two pieces of info needed to calculate an average (sum and count). You can see that the total number of grades isn't needed until the very end.
If you are stuck, try a smaller problem - prompt the user to enter a single grade and read it in. Then add a loop and have the user continue entering grades until they enter a special flag to say they are done.
J Rock wrote:So should i do the average in my main, or should i make a method for it?
Up to you. The average is only one line of code after all. I would focus on getting it working before worrying about something cosmetic like that*.
* Note this advice only applies while you are very new to Java. After a while, you'll have a feel for what goes in a method. And have longer programs. At which point, I no longer recommending dumping extra things in main().
Joined: Feb 27, 2010
Ok, another question i have, how could i make it so it prints out the lowest and the highest grade that it receives?
First of all you need something which would keep track of lowest and highest grades. Then every time the code receives a grade, it should ask whether that grade is now the lowest, or the highest. Printing those things out is of course the easy part.
J Rock wrote:Ok, another question i have, how could i make it so it prints out the lowest and the highest grade that it receive
Well, have you been able to do the average? Can you show us what you did? If not, it's probably better to concentrate on one part of the problem at a time.
Also, looking back at what you've shown so far... what happens in your method getLetterGrade() if the value of average is, say, 71.3? I mean, exactly what happens? Look through the code and try to predict the outcome. Then, compile it and run it, and see if you were right.
Actually, maybe that should have been the first question: does your code even compile? (For what you've shown above, no, it doesn't - but maybe you've fixed it since then.) If not, focus on why it doesn't compile, and fix it, before adding even more code. Otherwise you're just making problems harder and harder to diagnose. Compile and run your code frequently, with only small changes in between. That way, any time it was compiling, and then it stops compiling, you know that the error must be somewhere in the small changes you've added since last time. (Well, usually.) This makes it much easier to track down problems.
Joined: Feb 27, 2010
Well, i've been asking so many questions because i have to have it finished by tomorrow at midnight, and it compiles for me, but i really have done much except what is there because i've been doing other things
J Rock wrote:Well, i've been asking so many questions because i have to have it finished by tomorrow at midnight, and it compiles for me, but i really have done much except what is there because i've been doing other things
I'm not sure how we are to respond to this other than to encourage you to put other things to the side and now concentrate on this program and on learning Java (which is no easy task when you're just starting out). Oh and to also wish you luck!
Joined: Feb 27, 2010
Yea, thanks anyways, i'll just turn in what i got and just take that, next time i'll be sure to get to this earlier ;)
Joined: Mar 05, 2008
Fair enough. But we can also give more useful feedback if we see what you've done so far. I know for a fact that the code you showed initially does not compile, so if you now have something that does compile, please show us how it's been modified, and that might be a good starting point for further progress.