• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array Constructor Reference to Main  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have been struggling with this program all day, hoping for some help!

I have written out just about everything, but cannot seem to create a constructor that i can refer to in Main. Below are the two classes that i have created which include what i need (except a constructor). Could anyone show me how to do so?

Main Class



Age Class



So, I am trying to call the method "displayAges()" into the Main Class. However, I am running in to 2 problems:

1) I cant seem to create an accurate constructor

2) Im not even sure if the display method's equation in Main Class is correct.

Any life savers out there?
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch Travis!

You are *really* close.



needs to be



The public keyword is what says the constructor can be called from other classes.
 
Travis Westburry
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, that definitely makes sense. Thanks!
And what about the "theAges.displayAges(anArray[ages].length)" at the bottom of Main... Would that display all integers in my array?
 
Sheriff
Posts: 4293
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This method doesn't use the parameter ages and doesn't need it, so declare it without the parameter:

Then you can call it in main() like this:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!