This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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
Sheriff
Posts: 38572
661
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: 5136
138
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!