C: Programming Create a Java program UsePet. Your program must have a method tha
ID: 3919769 • Letter: C
Question
C: Programming Create a Java program UsePet. Your program must have a method that takes a Pet object and a String as input and returns true if the pet has a child with the name as given by the string, and false otherwise. Your program must create the following Pet object: Fluffy, a cat, who was born in 2012 She has two children: Igor, a cat, who was born in 2013 (who has no children) and Wei, an owl (who was adopted), who was born in 2014 (who has no children). Your program should then ask for user input (using a Scanner object) for a name. Using your method (from above), check if Fluffy has a child with the given name and output an appropriate message. If the user input was "Goran", the output should be one of yes, Fluffy has a child named Goran. or no, Fluffy does not have a child named Goran Do not hardcode"fluffy" in the output message. It should print whatever name the Pet object in your program has. Your program should work correctly no matter what Pet object we initially create. Do not hardcode your solution for the Fluffy pet. Do not create any UsePet objects. Potentially Useful Things java.util.Scanner has a next ) method that returns the next String token (word) from a given scanner object.Explanation / Answer
public class Pet { private String name; private String type; private int born; private Pet[] children; public Pet(String name, String type, int born, Pet[] children) { this.name = name; this.type = type; this.born = born; this.children = children; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getType() { return type; } public void setType(String type) { this.type = type; } public int getBorn() { return born; } public void setBorn(int born) { this.born = born; } public Pet[] getChildren() { return children; } public void setChildren(Pet[] children) { this.children = children; } } import java.util.Scanner; public class UsePet { public static boolean hasChild(Pet pet, String name) { for(int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.