• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getter/setter and methods  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone, I am new in this Forum and practically new in the Java language. I would like to get some advice for my java assignment. I have to create a java program using arrays. The user has to insert a series of values which later I will have to use "linear search" to locate this data inserted by the user and know where it is. But I have an error coming up which I cant solve. The linear id method is giving me an error on eclipse that I cant be recognised even though I have the method on the same folder. I would really appreciate someone to help me out. Please see the code below. Many thanks



 
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please quote the exact error you are receiving.
 
Al Cons
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Les Morgan wrote:Please quote the exact error you are receiving.


items = Linearid (items, scan);

The program cant see the method Linear id. As a result Linear id is shown with a red underline!

 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Al Cons wrote:
Les Morgan wrote:Please quote the exact error you are receiving.
The program cant see the method Linear id.


I don't believe that's the exact error. I believe it's your interpretation of the error. Please copy and paste the error message exactly -- in Eclipse there is a "Problems" tab where you can copy the text of the message.
 
Al Cons
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Al Cons wrote:
Les Morgan wrote:Please quote the exact error you are receiving.


items = Linearid (items, scan);

The program cant see the method Linear id. As a result Linear id is shown with a red underline!
I am using setters and getters to save item id, item name, item quantity and item value.



 
Saloon Keeper
Posts: 3336
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your method takes an array of int's but you are passing an array of Item's.
 
Al Cons
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Al Cons wrote:
Les Morgan wrote:Please quote the exact error you are receiving.
The program cant see the method Linear id.


I don't believe that's the exact error. I believe it's your interpretation of the error. Please copy and paste the error message exactly -- in Eclipse there is a "Problems" tab where you can copy the text of the message.

It might be my interpretation no doubt!. This is the problem tab error.





1.png
[Thumbnail for 1.png]
 
Al Cons
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Al Cons wrote:
Les Morgan wrote:Please quote the exact error you are receiving.
The program cant see the method Linear id.


I don't believe that's the exact error. I believe it's your interpretation of the error. Please copy and paste the error message exactly -- in Eclipse there is a "Problems" tab where you can copy the text of the message.

It might be my interpretation no doubt!. This is the problem tab error.


This is so far what I 've done
 
Sheriff
Posts: 11498
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are the relevant lines of code:




Eclipse is not finding the Linearid you're thinking it should find because the method signature of the method on line 58 doesn't match the types of the parameters that you use to invoke the method on line 23. The items parameter on line 58 is declared as an int[] whereas the items variable that you're passing on line 23 is declared on line 15 as an array of Item objects. Those two types are not compatible, so Eclipse thinks that you must be referring to some other version of Linearid, which it can't find. Likewise, the scan parameter on line 58 is declared as an int whereas the scan variable that you pass to the method call on line 23 is declared on line 7 as a Scanner. Again, these two types are not compatible and adds to Eclipse's confusion about what you meant to call.

So it's really a matter of you saying your method takes an int[] and an int as parameters, then turning around and trying to call that method with a Item[] and a Scanner object. Eclipse is politely telling you to get your types and method call straightened out.
 
Junilu Lacar
Sheriff
Posts: 11498
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, standard naming conventions dictate that you name that method linearId() instead of Linearid(). Method and variable names should start with a lower case letter, followed by camel case for any subsequent words in the name. Like what you have with print() and main() or in println() and in String.toUppercase().

Also, a boolean method should have a name that indicates it's nature as a true or false expression, such as isEmpty() or hasNext(). In this case, maybe isLinearId() or hasLinearId() would be a better name.
 
Junilu Lacar
Sheriff
Posts: 11498
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And while the following is legal:

the standard, and IMO, less confusing way to declare that is this:

Read that code out loud as "The items variable represents an array of Item objects." Note the symmetry in the left and right sides of this version vs the former.
 
Al Cons
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:And while the following is legal:

the standard, and IMO, less confusing way to declare that is this:

Read that code out loud as "The items variable represents an array of Item objects." Note the symmetry in the left and right sides of this version vs the former.


Hi Junilu Lacar, Thanks for responding to my issue. Would you mind to sort this part of the code for me? How would you fix it in order to use the linear code? I am a bit confuse! Many thanks again to you
 
Paul Clapham
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Al Cons wrote:This is the problem tab error.


For future reference: You can right-click on a problem description and get a popup menu including "Copy". If you select that option, you can then paste the problem description right into your post here on the forum. That's much more friendly and helpful than making somebody view an image containing microscopic text.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!