sorting through an array of objects

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2005
Posts: 3
Reputation: markymarkb1000 is an unknown quantity at this point 
Solved Threads: 0
markymarkb1000 markymarkb1000 is offline Offline
Newbie Poster

sorting through an array of objects

 
0
  #1
May 7th, 2005
Hi...I have created a private static main method which instantiates an array of 3 different types of objects depending on the choices entered in on the command line. Here is my code:

public static void main(String[] args)
{
//creates local variable currentIndex

//creates employee array of type worker which can hold up to 100 emloyee objects
Worker[] employee = new Worker[100];
//do/while loop
int i = 0;
do{
//if "w" for "worker" is entered, call Worker Class constructor, store
//pointer to worker name in employee array
if (args[i].equalsIgnoreCase("w"))
{
//store worker name in employee array
employee[currentIndex] = new Worker(args[i+1]);
//increment currentIndex counter by 1
currentIndex++;
//increment counter i by 2
i+=2;
}

//if "p" for "producer" is entered, call Producer Class constructor, store
//pointer to producer name and prod. target in employee array
else if (args[i].equalsIgnoreCase("p"))
{
//store producer name in next avail array slot, morph string value for
//production target and store as integer in next array slot
employee[currentIndex] = new Producer(args[i+1], Integer.parseInt(args[i+2]));
//increment currentIndex counter by 1
currentIndex++;
//increment counter i by 2
i+=3;

}
//if "m" for "manager" is entered, call Manager Class constructor, store
//pointer to manager name, number of subordinates, and whether or not this
//manager is liked in next array slot
else if (args[i].equalsIgnoreCase("m")){
//store manager name in next avail array slot, morph string value for
//number of subordinates and store as integer in next array slot along with
//liked/disliked result in following slot
employee[currentIndex] = new Manager(args[i+1], Integer.
parseInt(args[i+2]), args[i+3]);
//increment currentIndex counter by 1
currentIndex++;
//increment counter i by 2
i+=4;
}
else
{
//if choice was entered other than m,p,w, print error message
System.out.println("Must be M, P, or W");
//exit program
System.exit(1);
}
//end while loop
}while(i <args.length);
}
}//end class

I am supposed to create a private static method which is called by this main class once the array has been instantiated and called if the "Producer" class has an integer value greater than 50 (this is the parseInt(args[i+2]) in the Producer constructor call).

I can't quite get it to work.

Am trying to use this code:

for (int j =0; j < employee.length; j++){
if (employee[j].equals("Producer"))
{
System.out.println(Producer(args[j+1], (args[j +1], Integer.parseIntargs[j+2]));

}
}

I keep getting an error - cannot resolve method Producer(java.lang.string, int)

any help?

thanks.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: sorting through an array of objects

 
0
  #2
May 7th, 2005
If producer is static, then you shouldn't be calling it using the new keyword. It should be, ClassName.methodName().

I would have thought that would cause a "non static method being called from a static context" error though. Since that wasn't your error, then it could be that your method signature isn't correct, or that the parameter list isn't correct.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: sorting through an array of objects

 
0
  #3
May 7th, 2005
By the way, use code tags so your code is easier to look at.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC