I need help as soon as possible please hs to with arrays.

import java.util.Random;

publicclass AviarySimulator

{

// Instance variables

private Aviary aviary;

privateint numberOfDays = 0;

private Random r;

publicvoid simulateDay(int amtFeed)

{

//a new Day

numberOfDays++;

System.out.println("**************************");

System.out.println ("Day : " + numberOfDays);

if(!aviary.isEmpty())

{

// Ask the cage to supply its budgie object

Budgie theBudgie = aviary.getBudgie();

/* Check there really is a Bird in the cage. null means that there is no

* bird object assigned to the myBudgie variable in class cage.

*/

if(theBudgie !=null)

{

// Code moved from below. PR

// Budgie gets older because a day has gone by.

theBudgie.incAge();

// Budgie exercises every day PR

theBudgie.exercise(DAILY_EXERCISE);

// Feed the budgie

// To avoid feeding nothing, check that food is given PR

// Also rejects negative feed!

if(amtFeed > 0)

{

theBudgie.eat(amtFeed);

System.out.println("Just been fed " + amtFeed +" grams of bird seed");

}

// Check if the budgie is still alive

if(theBudgie.isDead())

{

System.out.println(theBudgie.getName() +" just died...sob");

System.out.println("Here lies " + theBudgie.getName() +" this budgie was much loved by its " +

theBudgie.getNumEggsLaid() +" eggy ofspring");

aviary.removeBudgie();

}

// If alive is it overweight?

elseif(theBudgie.isObese())

{

System.out.println(theBudgie.getName() +" is obese it needs some exercise");

theBudgie.exercise(10);

}

else// Budgie is alive and not overweight

{

System.out.println(theBudgie.toString());

// The budgie gets a day older

// theBudgie.incAge(); // Moved to above PR

// The budgie may lay an egg

if(theBudgie.layEgg(r))

{

System.out.println(theBudgie.getName() +" has just laid an egg ");

System.out.println("The egg has been removed from the cage for artificial incubation \n"

+"and will be adopted out after hatching");

}

}

}

}

else// No budgie in the cage

{

System.out.println("The cage is empty");

}

}

//--

/**

* Simulate several days without food.

* @param numDays, the length of the simulation

*/

publicvoid simulateDays(int numDays)

{

for(int i = 0; i < numDays; i++)

{

simulateDay(0);// PR

}

}

//--

/**

* Simulate several days with food.

* @param numDays, the length of the simulation

* @param amtFeed, the amount of budgie food in grammes

*/

publicvoid simulateDays(int numDays,int gmsSeed)

{

for(int i = 0; i < numDays; i++)

{

simulateDay(gmsSeed);

}

}

//--

}

This code is supposed to be compatible with this code:

public Budgie(String name,boolean female)// Added gender PR

{

// Initialise instance variables

age = 0;

colour ="green";// Default colour

canTalk =false;// Cannot talk yet, can only go "cheep"

// Quotes removed PR

budgiesWords ="cheep";

weight = 25;// In healthy weight range

bIsFemale = female;// PR

water = 10;

// Record supplied name

this.name = name;

}

//--

/**

* Teaches a budgie to talk

* @param phrase - what the budgie can say

*/

publicvoid teachToTalk(String phrase)

{

// Ignore an empty string

if(phrase !="")

{

// Budgie can now talk

canTalk =true;

budgiesWords = phrase;

}

}

//--

/**

* Increments a budgie's age by a day

*/

publicvoid incAge()

{

age++;

}

//--

/**

* The budgie is dead if it is too old or too fat or starved or too thirsty.

*/

publicboolean isDead()

{

return (diedOfOldAge() || diedFromOverFeeding() || isStarved() || diedOfThirst());

}

//--

/**

* The budgie is too old if it is older than the budgie's maximum age.

*/

publicboolean diedOfOldAge()

{

return (age > MAX_AGE);

}

//--

/**

* The budgie is too thirsty if it is has less than 10mls of water.

*/

publicboolean diedOfThirst()

{

return (water < MIN_DRINK);

}

//--

/**

* The budgie is too heavy to live if it is more than double a

* budgie's sensible weight limit.

*/

publicboolean diedFromOverFeeding()

{

return (weight >= TOO_FAT*2);

}

//--

/**

* The budgie is obese if it is more than a budgie's sensible

* weight limit.

*/

publicboolean isObese()

{

return (weight >= TOO_FAT);

}

//--

/**

* The budgie is starved if it is less than a budgie's sensible

* minimum weight.

*/

publicboolean isStarved()

{

return (weight <= TOO_THIN);

}

//--

/**

* The budgie has been fed. It will put on weight.

* @param gmsOfBirdFeed, the amount of food eaten in grammes

*/

publicvoid eat(int gmsOfBirdFeed)

{

// Convert to gms fat

double fat = gmsOfBirdFeed/10.0;

weight = weight + fat;

}

//--

/**

* The budgie has drunk.

* @param mlsofwater, the amount of water drunk in mls

*/

publicvoid drink(int mlsOfWater)

{

water = mlsOfWater;

}

//--

/**

* The budgie has done some exercise. It will lose weight.

* @param minutesOfExercise, the time of the exercise

*/

publicvoid exercise(int minutesOfExercise)

{

double weightLoss = minutesOfExercise * 0.1;// For each minute lose 0.1 gms fat

weight -= weightLoss;

System.out.println("Budgie exercising for " + minutesOfExercise +" minutes, has lost " + weightLoss +" grammes in weight." );

}

//--

/**

* The budgie may lay an egg. Only adults can lay eggs.

* @param rnd, a random object

*/

publicboolean layEgg(Random rnd)

{

boolean bLaying =false;// default

// Only hens can lay eggs // PR

if(bIsFemale)

{

int probability = rnd.nextInt(10);

// Random chance that it will lay

// Added that cannot lay if last egg laid yesterday PR

if((probability >= 5) && (age > ADULT_AGE ) && (age - lastEgg != 1))

{

// Can only lay eggs if a grown-up

numEggsLaid++;

bLaying =true;

lastEgg = age;// Laid an egg today PR

}

}

return bLaying;

}

//--

/**

* The budgie talks - display its words.

*/

publicvoid talk()

{

System.out.println(budgiesWords);

}

//--

/**

* Change the colour of the budgie.

* @param newColour, new value of budgie's colour

*/

publicvoid setColor(String newColour)

{

colour = newColour;

}

//--

/**

* Return the colour of the budgie.

* @return budgie's colour

*/

public String getColour()

{

return colour;

}

//--

/**

* Output the budgie's details.

* @return A string containing all details of the budgie

*/

public String toString()

{

String msg ="Budgie " + name +" ";

if(canTalk)

{

msg +="can talk it says ";

}

else

{

msg +="can not talk it just makes the sound ";

}

msg +="'" + budgiesWords +"'";

msg +="\n";

msg +=" Its colour is : " + colour;

msg +="\n Its age is : " + age +" days.";

return msg;

}

//--

/**

* Return the number of eggs the budgie has laid.

* @return eggs laid by budgie

*/

publicint getNumEggsLaid()

{

return numEggsLaid;

}

//--

/**

* Return the budgie's age.

* @return age of budgie

*/

publicint getAge()

{

return age;

}

//--

/**

* Return the budgie's name.

* @return name of budgie

*/

public String getName()

{

return name;

}

//--

/**

* Return the budgie's gender.

* @return true if budgie is female

*/

publicboolean isFemale()

{

return bIsFemale;

}

//--

}

But everytime Itry to compile it highlightthis bit in the simulator:

Budgie theBudgie = aviary.getBudgie();[code]

With an error message:

getBudgie in Aviary cannot be applied to ()

Im sorry for the long post please help would be most apreciated.

[17720 byte] By [gggmana] at [2007-10-2 20:37:59]
# 1
Show class Aviary.
Michael.Nazarov@sun.coma at 2007-7-13 23:21:18 > top of Java-index,Java Essentials,Java Programming...
# 2

NO prob man thank for such a quick response

import java.util.ArrayList;

/**

* A Aviary for budgies to live in.

* A maximum of one budgie can live in aviary

* @author (Jacqui Whalley)

* Modified by Phil Robbins

* @version (v0.2)

* 9-3-2006 Fixed bugs from stage 1.

*Added stage 2 code

*/

public class Aviary

{

// Instance variables

private ArrayList budgies; // The budgies that live in the aviary

// private boolean empty;// Removed PR

//--

/**

* Constructor for objects of class aviary.

*/

public Aviary()

{

//empty = true; // removed PR

budgies = new ArrayList(); // Semi colon added PR

}

//--

/**

* Add a budgie to the aviary.

* @param bird, the budgie to add to the aviary.

*/

public void addBudgie(Budgie bird)

{

// Can only have one budgie

budgies.add(bird);

}

//--

/**

* Remove the budgie - eg if it has died.

*/

public void removeBudgie(int index)

{

if (index <= budgies.size() && index > 0)

{

// Can only remove if there is a budgie there

budgies.remove(index);

}

else

{

System.out.println("Error");

}

}

//--

/**

* Returns the Aviary's budgie (which my be null).

* @return The budgie that lives in the Aviary

*/

public void getBudgie(int index)

{

if (index <= budgies.size() && index > 0)

{

// Can only remove if there is a budgie there

System.out.println(budgies.get(index));

}

else

{

System.out.println("Error");

}

}

//--

/**

* Returns true if the cage is Aviary.

* @return the emptiness of the Aviary

*/

public boolean isEmpty()

{

//return empty; // Removed PR

return budgies.size() == 0;

}

//--

/**

* List budgies and there details

*/

public void listBudgieDetails()

{

for(int i = 0;i < budgies.size();i++)

{

System.out.println(budgies.get(i));

}

}

}

gggmana at 2007-7-13 23:21:18 > top of Java-index,Java Essentials,Java Programming...
# 3
See the addBudgie method declaration of Aviary class.It takes a one argument but you are not passing that in the line that you get the error
LRMKa at 2007-7-13 23:21:18 > top of Java-index,Java Essentials,Java Programming...
# 4
ok so I changed the error code to: Budgie theBudgie = aviary.getBudgie(int index);but now it comes with an error: '.class' expected
gggmana at 2007-7-13 23:21:18 > top of Java-index,Java Essentials,Java Programming...
# 5
Budgie theBudgie = aviary.getBudgie(index);whithout "int"! Read about syntax...
Michael.Nazarov@sun.coma at 2007-7-13 23:21:18 > top of Java-index,Java Essentials,Java Programming...
# 6

The following test is wrong:

> if (index <= budgies.size() && index > 0)

If 'n' budgies are stored in your list they have index values 0, 1, 2, ... n-1.

Change the test as follows:

if (index < budgies.size() && index >= 0)

kind regards,

Jos

JosAHa at 2007-7-13 23:21:18 > top of Java-index,Java Essentials,Java Programming...