Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Instructions Modify the Cat class lab to make all data private, include setters and getters, and create two different Cat objects in a separate Main
Instructions Modify the Cat class lab to make all data private, include setters and getters, and create two different Cat objects in a separate Main class. In the Main class, do the following: - Create a cat object with reference variable "Garfield" - Create another cat object with reference variable "Crookshanks" - Set Garfield's age to 7 - Set Crookshanks' age to 11 - Check if Garfield and Crookshank are "old" (older than 10 years old) - Check if Garfield and Crookshank are the same age. Please submit .java or zip file (not just screenshot) From previous lab: - Create a class named 'Cat'. - Add an integer field named 'age' to class Cat. - Add a method 'getAge()' to class Cat that returns the current value of the field 'age'. - Add a method 'void setAge(int newAge)' to class Cat that sets the field 'age' to a new value. - Add a method 'void setAge(String newAge)' to class Cat that sets the int field 'age' to a new value. Use Integer.parselnt("some string") to convert a string to an int. - Add a method 'boolean isOld()' to class Cat that returns true if the cat's age is greater than 10. - Add a method 'boolean sameAge(Cat anotherCat)' to the class Cat that returns true if the other cat is the same age as this instance. - Add a method 'void birthday()' that increases the int field age by 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started