• 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

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yeah, but is it art? What do you think tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic