• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I store an array with count when my method is void?  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 4935
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question is not clear.

1. About which void method you are talking?
main or aAdd? (they are both void)

2. On Line 8 you stated that you having error. What kind of error you having?
Would you mind to post it here? Error messages usually contains important information about what is wrong.

3. Line 43 - missing semi colon after count
Maybe this is your error?



 
Pete MyMy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.qAdd()

2. method qAdd in class cannot be applied to given types.
required:no arguments;.....

I want to keep value of the array inside the count.
Eg..
When I select the option 1, it will go to method gAdd. It will count everytime I go to option 1 until it is full in the array.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Does that qAdd method compile? you should call a method with arguments which match its parameters. I think you do want to call it with three arguments in which case that method would have three parameters.

But I can see another problem. Why have you marked the method static? Why are the array and the count not instance fields? Why have you got such a long method? Even worse than a long method is a long main method. I think you are writing non‑object oriented code and you need to design a class which encapsulates that array and the count and provides access via add methods. Then you can call add on its objects.
 
Pete MyMy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. My program is an not object oriented prog.

I need the user to selection the option. After that go to the next page and add names till array is full and message will display full. If it is not full, it will update the count and display the position of the adding.
I'm kinda lost on why I can't add the array inside the count?

Sorry,but I don't get your explanation. Is there any example to explain?
 
Liutauras Vilda
Sheriff
Posts: 4935
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete, what Campbell Ritchie mentioned in his first sentences:

In this case at line 2 you cannot pass any arguments to a method, as you didn't specify them in your method as parameters, when you declared your method.

If you still want to supply them, then you need to do on line 4:




 
Pete MyMy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I shift the public static void qadd...,just below the count?
I'm having illegal start of expression.
 
Saloon Keeper
Posts: 3331
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where you had qAdd() was just fine. What you didn't have is the call to qAdd(name,"den",count) on line 8 matching the argument list in qAdd() on line 33. Although the argument list in your call to qAdd() on line 22 matches, I don't think this is what you want because you are not passing in what you want to add and you're not getting back the new count. You need to rethink qAdd() on line 33, if "count" is local to this method it will disappear when the method returns which is not what you want. Likewise, "name" on line 36 should have been an array but you still don't want it to disappear when the method returns.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!