So I'm back, after a 4am night last night and no result on this assignment! Basically I'm doing the driver exam assignment. Our teacher provides demo program that allows driver input of answers and displays result. We have to write the class that includes a method to return # of correct, # of incorrect and an array of the numbers of the questions missed. I struggled with this like crazy yesterday, trying to work out how to return the numbers of the unanswered questions when validation in the demo didn't allow unanswered. My teacher has now clarified, that by 'array of questions missed' he actually means 'an array of incorrect questions'. So to sum up - I need to write a class that provides # of correct, pass/fail, # of incorrect and a list of the question numbers pertaining to those incorrect answers. So far I have the total correct working, the pass/fail working and the total incorrect count working, but I just really don't understand arrays well enough (despite reading every forum between here and the moon) to understand how I can return the list of question numbers of incorrect - Please someone help me, I'm ready to throw my computer at a wall and give up this degree. I'm just an absolute complete beginner and just need a little help please. Those of you I spoke to yesterday understand!
Below is my class, for which I am getting the error 'compatible types, int cannot be converted to integer - return missed' - I think this means I need some sort of else statement but I've tried that and get a handful of extra errors. Below my class is the teacher's demo, and no matter what I do, I can't run it without getting the error 'incompatible types int cannot be converted to int missedQuesions = exam.Missedquestions().
This may seem the dumbest thing in the world to you, and I'm sorry if it's wasting your time, but I'm at my wits end!
Demo which also gets that conversion error listed above
amanda allen wrote:
The error I get for my class is:
DriverExam.java:44: error: incompatible types: int cannot be converted to int
You can't returned the "missed" local variable. It is declared as an array, and the method is defined to return an int. Also, a few lines down, you can't return an null either, as null is not a valid int value (and again, the method is defined to return an int).
Thanks Henry, I think we spoke last night. I understood from the error that this was what was going on, the problem is I don't know how to fix it. I know i have to return an array when the demo program calls for it, but I just can't figure out how to do this from my class - and you know I've been trying night Likewise, I understand in the demo error that one is an int and one is an array, but my teacher wrote that and it works for everyone else, so it must work, I just can't make it work. Any advice?
posted 5 years ago
I just changed the questionsMissed() method in my class and it is now able to compile (though I'm still getting that same error in the demo so I don't actually know if it works.
My new code for the questionMissed() method is ,below, but I can't see how it would even return the values to the missed array - would it?