Here is the source code for the Kitty class:

public class Kitty {

String name;
int age;

public Kitty(){
}

public void setName(String n){
name = n;
}

public String getName(){
return name;
}

public void setAge(int a){
age = a;
}

public int getAge(){
return age;
}
}

1) The array myCats is an 8 element array of type Kitty that has already been declared and initialized. Write the expression(s) in the box below that increases the age of the fifth Kitty by one year:

(Remember: the first element of an array is at index position 0).

2)The array myCats is an 8 element array of type Kitty that has already been declared and initialized. Write the expression(s) in the box below that prints to the console the name of the fourth Kitty if its age is strictly greater than the age of the fifth Kitty, and prints the name of the fifth Kitty otherwise:

(Remember: the first element of an array is at index position 0).

2 answers

The fifth Kitty is myCats[4], since the index starts from zero.
Each member of the array myCats is a Kitty object.

1)
To increase the age, you need to get the age of myCats[4], add one to it, and put back the increased age. This is how you can do it:
myCats[4].setAge(myCats[4].getAge()+1);

2)
int age4=myCats[3].getAge();
int age5=myCats[4].getAge();
if(age4>age5)
{
System.out.print(myCats[3].getName());
} else
{
... to be completed by you ...
}
System.out.print(myCats[4].getName());
Similar Questions
  1. (Excerpt from Chapter 7 of Anna Karenina, by Leo Tolstoy)12. The suspense in this passage primarily derives from which of the
    1. answers icon 2 answers
  2. using System;namespace RecipeApp { class Recipe { public string[] Ingredients { get; set; } public string[] OriginalIngredients
    1. answers icon 1 answer
  3. using System;namespace RecipeApp { class Recipe { public string[] Ingredients { get; set; } public string[] Steps { get; set; }
    1. answers icon 1 answer
  4. using System;namespace RecipeApp { class Recipe { public string[] Ingredients { get; set; } public string[] Steps { get; set; }
    1. answers icon 1 answer
more similar questions