Java
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.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here