I have two classes. A class called Cat, that holds the cat names, birth year and weight in kilos. I have a class called Cattery that is an array. I want to input cats from the Cat class into the array. Each cat will have its own name, birth year and weight in Kilos. How do I do this? Thank you.
public class Cat {
private String name;
private int birthYear;
private double weightInKilos;
/**
* default constructor
*/
public Cat() {
}
/**
* @param name
* @param birthYear
* @param weightInKilos
*/
public Cat(String name, int birthYear, double weightInKilos){
this.name = name;
this.birthYear = birthYear;
this.weightInKilos = weightInKilo
}
/**
* @return the name.
*/
public String getName() {
return name;
}
/**
* @return the birthYear.
*/
public int getBirthYear() {
return birthYear;
}
/**
* @return the weightInKilos.
*/
public double getWeightInKilos() {
return weightInKilos;
}
/**
* @param the name variable.
*/
public void setName(String newName) {
name = newName;
}
/**
* @param the birthYear variable.
*/
public void setBirthYear(int newBirthYear) {
birthYear = newBirthYear;
}
/**
* @param the weightInKilos variable.
*/
public void setWeightInKilos(double newWeightInKilos) {
weightInKilos = newWeightInKilos;
}
}
The array class.
import java.util.ArrayList;
public class Cattery {
private ArrayList<Cat> cats;
private String businessName;
/**
* @param Cattery for the Cattery field.
*/
public Cattery() {
cats = new ArrayList<Cat>();
this.businessName = businessName;
}
/**
* Add a cat to the cattery.
* @param catName the cat to be added.
*/
public void addCat(Cat name)
{
Cat.add(getName());
}
/**
* @return the number of cats.
*/
public int getNumberOfCats()
{
return cats.size();
}
}
cats.add(new Cat(...))?