Jiskha Homework Help
SATURDAY
November 21, 2009
SCHOOL SUBJECTS
- Art
- Business
- Computers
- English
- Foreign Languages
- Health
- Home Economics
- Math
- Music
- Physical Education
- Science
- Social Studies
GRADE LEVELS
- Preschool
- Kindergarten
- Elementary School
- 1st Grade
- 2nd Grade
- 3rd Grade
- 4th Grade
- 5th Grade
- 6th Grade
- 7th Grade
- 8th Grade
- High School
- 9th Grade
- 10th Grade
- 11th Grade
- 12th Grade
- College
- Adult Education
Post a New Question | Current Questions | Chat With Live Tutors

Homework Help Forum: Programming

Posted by Rob on Wednesday, October 28, 2009 at 2:17am.

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).


  • Programming - MathMate, Wednesday, October 28, 2009 at 8:05pm

    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 ...
    }

Answer this Question

First Name:
School Subject:
Answer:

For Further Reading

SEARCH

COMMUNITY
FEATURES
- Live Tutors
- Net Riddle
- Reference
- Search