I am creating this program for class and i need to change the values of the 2nd object(c2) and just that individual object. The values i want which field to hold are
name = mittens
isDeclawed = true
species = sabertooth
I don't know how to specifically change the c2 object. can someone point me in the right direction?
And where i instantiate (ignore the other classes for which they refer to a different problem)
name = mittens
isDeclawed = true
species = sabertooth
I don't know how to specifically change the c2 object. can someone point me in the right direction?
Code:
public class Cat
{
private String name;
private boolean isDeclawed;
private String species;
//DEFAULT CONSTRUCTOR
//SETS NAME TO ------, isDeclawed TO FALSE, SPECIES TO " ";
public Cat()
{
name= "------";
isDeclawed= false;
species = "------";
}//end Cat.
public Cat(Cat c)
{
setName(c.getName());
setIsDeclawed(c.getIsDeclawed());
setSpecies(c.getSpecies());
}//end copy constructor
//MUTATOR METHODS
public void setName(String na) {name = na;}//end setname
public void setIsDeclawed(boolean dc) {isDeclawed=dc;}//end setIsDeclawed
public void setSpecies(String sp) {species=sp;}//end setSpecies
//ACCESSOR METHODS
public String getName() {return name;}//end getName
public boolean getIsDeclawed() {return isDeclawed;}//end getIsDeclawed
public String getSpecies() {return species;}//end getSpecies
//Prints the values of the object c1.
public String toString()
{
String s ="Name:\t\t"+getName()+ "\n"+
"Declawed?:\t"+getIsDeclawed()+"\n"+
"Species:\t"+getSpecies();
return s;
}
}//end CAT
And where i instantiate (ignore the other classes for which they refer to a different problem)
Code:
public class assignment2Problem1Test
{
public static void main(String[]args)
{
testProblemOne();
}//end main
//creates an array of size 200
public static void problemTwo()
{
Cat catArray [] = new Cat[200];
int count = 0;
for(int i=0;i<200;i++)
{
catArray[i] =new Cat();
count++;
System.out.println(catArray[i]+"Number:\t"+count);
}//end FORLOOP
System.out.println(catArray[2]);
}
public static void testProblemOne()
{ Cat c1 =new Cat();
Cat c2 =new Cat();
System.out.println(c2);
}//end testProblemOne.
}//end assignment2Problem1Test