reate a class named Pet with the following data fields: String name; String type; int age; Create get and set methods for all of the data fields. Also, create a non-default constructor so that users can initialize a Pet object using inputs for name, type, and age. Also, create a non-static method named speak. This method will check the type of the Pet object and return a String with a corresponding sound. If the data field type is "cat", it will return "Meow!" If the data field type is "dog", it will return "Woof!" If the data field type is "cow", it will return "Moo!" If the data field type is "seahorse", it will return "Weesnaw!" If the data field type is anything else, it will return "?????" Once your class is written, write another class named TestPet, which will be used to test your class. Make sure the following things are tested within this TestPet program: 1. The non-default constructor functions properly. 2. The set and get methods function properly. 3. The speak method function properly.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 11PE
icon
Related questions
Question

Create a class named Pet with the following data fields:

String name;

String type;

int age;

Create get and set methods for all of the data fields.

Also, create a non-default constructor so that users can initialize a Pet object using inputs for name, type, and age.

Also, create a non-static method named speak. This method will check the type of the Pet object and return a String with a corresponding sound.
If the data field type is "cat", it will return "Meow!"
If the data field type is "dog", it will return "Woof!"
If the data field type is "cow", it will return "Moo!"
If the data field type is "seahorse", it will return "Weesnaw!"
If the data field type is anything else, it will return "?????"

Once your class is written, write another class named TestPet, which will be used to test your class. Make sure the following things are tested within this TestPet program:
1. The non-default constructor functions properly.
2. The set and get methods function properly.
3. The speak method function properly.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage