Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java please The base class Pet has protected fieids petName, and petAge. The derived class Cat extends the Pet class and includes a private field
java please
The base class Pet has protected fieids petName, and petAge. The derived class Cat extends the Pet class and includes a private field for ciatireed Complete main0 to: - create a generic pet and print information using printinfo0 - create a Cat pet, use printinfo0 to print information, and add a statement to print the cats torend using the getBreedo method. Ex. If the input is Dobby 2 kreachos scottish Fold the ourput is pet Tnfoemation: Hame: Dabby Xge: 2 fiot informations Whmes. Kreacher Age: 3 Fietal Scattiah fold 1 public class Cat extends Pet if private String breed; public void setBreed(String userBreed) \{ \} breed = userBreed; public String get8reed() i return breed; ) ) File is marked as read only Current file: Pet.java - public class Pet \{ protected String nome; protected int age; public void setName(String userName) i \} name = userName; public String getName of return name; \} public void setAge(int userAge) f age - userAge; 14 public void setAge(int userAge) \& 15 age - userAge; ) public int getAge( 1 ) return oge; public void printinfo() i System, out,println("Pet Information: "); System, out,println(" Name: " + name); System,out.println(" Age: "+ age); J 9! inport jova.util. Scanner; pubtic class Petinformotion if public stotic void main(String args) [ Scanner scne = new Scanner(Systen.in); Pet myPet = new Pet( ; Cat myCat = new Cot(; String petNane, catNare, catBreed; int petage, catAge; petNane - scnr, nextline O; petAge =scnr, nextint () ; scnr, nextline O; Current file: Petinformation.java . Load default teme petAge =scnr, nextint O; scnr, nextLineO; cathame = scnr, nextLine( ; catAge - scnr, nextInt O : scrir.nextline(); catBreed - 5cnr, nextline O : II rOoO: (reate generic pet (using petMame, petAge) and then call printinfo II ToDO: Create cat pet (using catName, catAge, catBreed) and then call printinfo 1/ TOOO: Use getBreed 0 , to output the breed of the cat \} \}) 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