Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pet information (derived classes) The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet class and includes a

Pet information (derived classes) The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet class and includes a private field for dogBreed. Complete the main() to:

  • create a generic pet and print information using printInfo().
  • create a dog pet, use printInfo() to print information, and add a statement to print the dog's breed using the getBreed() method.

Ex. If input is:

Dobby2Kreacher3German Schnauzer

the output is:

Pet Information: Name: Dobby Age: 2Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzer
imageimageimage

Current file: Petinformation.java Load default template... 8 int petAge, dogAge; 9 10 11 petAge scnr.nextInt(); 12 petName = scnr.nextLine(); scnr.nextLine(); 13 dogName scnr.next(); 14 dogAge scnr.nextInt(); 15 16 17 18 19 20 21 22 scnr.nextLine(); dogBreed scnr.nextLine(); // TODO: Create generic pet (using petName, petAge) and then call printInfo // TODO: Create dog pet (using dogName, dogAge, dogBreed) and then call printInfo // TODO: Use getBreed(), to output the breed of the dog 23 24 } 25}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

The base clan Pethan protected fields peame and petge The derived class Dog extend the Pats and incl... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java Programming

Authors: Joyce Farrell

9th edition

1337397075, 978-1337397070

More Books

Students also viewed these Programming questions