• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Driver Exam - returning arrays and int vs int[] conversion issue

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't quite have your code tags right, so I fixed them for you.

Can you please post the full and complete error message? It should tell you what line the compiler thinks the error is on. that helps in diagnosing the actual issue.
 
amanda allen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Damn! I can't even get the code tags right even though I keep trying!

The error I get for my class is:
DriverExam.java:44: error: incompatible types: int[] cannot be converted to int
return missed

1 error

The Demo error is:
DriverExamDemo.java:43: error: incompatible types: int cannot be converted to int[]
missedQuestions = exam.questionsMissed();


I'm not completely in the dark, I do get what they are telling me, I just can't seem to fix them to get this whole show to run.

Thanks in advance!

A
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

amanda allen wrote:
The error I get for my class is:
DriverExam.java:44: error: incompatible types: int[] cannot be converted to int
return missed



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).

Henry
 
amanda allen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

A
 
amanda allen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's not

[java code]

but

[ code=java]

(without the space.

You can also highlight your block of code, then click the "code" button up at the top.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic