473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help with objects and arrays...

I hope someone can help.

I am trying to write a Java program that will pass an Int-type, String-type and an object into an array that will loop 100 times, filling it with the items in parentheses. I have no clue how to accomplish this as I am brand new to Java and to programming in general. The last method is the one I need help filling. Please help!!

public class Locator
{
// array sizes (and limits)
private final static int STORE_LIMIT = 100;
private final static int POSTAL_ZONE_LIMIT = 100;

// instance variables
Store [] storeArray;
PostalZone [] postalZoneArray;
private int nextStore;
private int nextPostalZone;

/**
* Constructor for objects of class Locator.
*/
public Locator()
{
storeArray = new Store[STORE_LIMIT];
postalZoneArray = new PostalZone[POSTAL_ZONE_LIMIT];
}

/**
* addStore - add a store to the array of stores.
*
* @param inputStoreNumber int Store number to add
* @param inputDescription String Store description to add
* @param inputLocation String Location of store
*
* @return int index of added store, -1 if unable to
* add (array already full)
*/

public int addStore(int inputStoreNumber, String inputDescription,
Location inputLocation)
{


}

TIA,
Dave
Jul 8 '06 #1
1 2324
D_C
293 100+
First, thanks for actually having a nice concise question, although you could have used [ code] and [/code ] tags (with no spaces between the brackets) to preserve whitespace.

I don't see where Store is defined, I'm assuming something like this:
Expand|Select|Wrap|Line Numbers
  1. class Store
  2. {
  3.   private int num;
  4.   private String desc;
  5.   private String loc;
  6.  
  7.   Store(int number, String description, String location)
  8.   {
  9.     num = number; 
  10.     desc = description;
  11.     loc = location;
  12.   }
  13.   ...
  14. }
Expand|Select|Wrap|Line Numbers
  1. /**
  2. * addStore - add a store to the array of stores.
  3. *
  4. * @param inputStoreNumber int Store number to add
  5. * @param inputDescription String Store description to add
  6. * @param inputLocation String Location of store
  7. *
  8. * @return int index of added store, -1 if unable to
  9. * add (array already full)
  10. */
  11.  
  12. public int addStore(int inputStoreNumber, String inputDescription, Location inputLocation)
  13. {
  14.   if(nextStoreIndex == STORE_LIMIT)
  15.     return -1;
  16.   storeArray[nextStoreIndex++] = new Store(inputStoreNumber, inputDescription, inputLocation);
  17.   return (nextStoreIndex-1);
  18. }
Jul 10 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ABC | last post by:
I am not a javascript guru or anything so I was wondering if someone could tell me what the code below is doing. Is it creating a multidimensional array? Would it be better to create an object? ...
2
by: don | last post by:
My question is, do C++ array of objects hold the objects or just the pointers to the objects..... I know Java arrays only hold pointers to objects, but I seem to remember that C++ arrays hold the...
5
by: Gent | last post by:
I have two questions which are very similar: Is it possible to return an object in C++. Below is part of my code for reference however I am more concerned about the concept. It seems like the...
13
by: Ben | last post by:
I have a program which is using a lot of memory. At the moment I store a lot of pointers to objects in std::vector. (millions of them) I have three questions: 1) Lets say the average Vector...
4
by: Mingus Tsai | last post by:
Hello- please help with unpickling problem: I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows XPhome system. My problem is with using cPickle to deserialize my pickled...
5
by: Gomaw Beoyr | last post by:
Hello Is there any explanation why Microsoft chose to implement arrays as objects allocated on the heap instead of structs allocated on the stack? For "mathematical stuff", one normally...
25
by: Jack | last post by:
Hi, Is there a general solution for the following problem: I have an array of instances of class B. Class B is publicly derived from class A. Then I have a class named Buffer that generally...
7
by: Sheldon | last post by:
Hi, I have the following loop that I think can be written to run faster in Numeric. I am currently using Numeric. range_va = main.xsize= 600 main.ysize= 600 #msgva is an (600x600) Numeric...
1
by: Mike Kent | last post by:
The APL 2007 conference, sponsored by ACM SIGAPL, has as its principal theme "Arrays and Objects" and, appropriately, is co-located with OOPSLA 2007, in Montreal this October. APL 2007 starts...
2
by: Dr Dav | last post by:
Hello all, I'm a physicist whose rewriting a numerical simulation, previously written in IDL, in C with the goal reducing runtime. As you may imagine, my C programming skills are quite poor but I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.