A little help for n00b? (Incompatible types)

Hi all. Java n00b here,

Taking an introductory course and am working on a simple program that involves calculating the average of three test scores. The main purpose of the assignment is to acquaint us with input and output panes. Got that fine, but I seem to be having issues with operations:

Re: A little help for n00b? (Incompatible types)

As the error said, "incompatible types", clearly it means that there are types incompatibility in your code. Java is a static-typed language. Once a variable given a type it cannot change. A string will always be string, an integer will always an integer. So you can't add three string variables and expect it become an integer for instance and then divide it. You need to convert those strings to numerals (integer) first and then you can do the calculation.

Re: A little help for n00b? (Incompatible types)

Hi Praetorian, welcome to the forums!

When you post code, use the "code" tags. Put [code] at the start of the code and [/code] at the end so that formatting is preserved. There are other formatting tags you can use described here: BB Code List - Java Programming Forum

-----

In your updated code you attempt to convert from a string to a double value. But, as wsaryada says, variables have a static type, so to do this conversion you might need two variables - one corresponding to the string that showInputDialog() returns and another one corresponding to the double returned by parseDouble().

Re: A little help for n00b? (Incompatible types)

I'm glad you've got it sorted out! Don't forget the [code] ... [/code] tags - you should be able to edit your post to add them. (There's an "Edit Post" link at the bottom of the panel where the post appears).