Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; public class PetInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String petName, dogName, dogBreed; int petAge, dogAge; petName

image text in transcribed

import java.util.Scanner;

public class PetInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in);

String petName, dogName, dogBreed; int petAge, dogAge;

petName = scnr.nextLine(); petAge = scnr.nextInt(); scnr.nextLine(); dogName = scnr.next(); dogAge = scnr.nextInt(); scnr.nextLine(); dogBreed = scnr.nextLine(); Pet myPet = new Pet(petName, petAge); Dog myDog= new Dog(dogName, dogAge, dogBreed); myPet.printInfo(); myDog.printInfo();

/ew dog myDog.setName("Thor"); myDog.setBreed("Boxer"); myDog.setAge(1); myDog.printInfo(); } }

Pet.java

public class Pet {

protected String petName; protected int petAge; //constructors public Pet() { petName="None yet"; petAge=0;} public Pet(String n, int a) {petName = n; petAge=a; } public void setName(String userName) { petName = userName; }

public String getName() { return petName; }

public void setAge(int userAge) { petAge = userAge; }

public int getAge() { return petAge; }

public void printInfo() { System.out.println("Pet Information: "); System.out.println(" Name: " + petName); System.out.println(" Age: " + petAge); }

}

Dog.java

public class Dog extends Pet { private String dogBreed;

}

The base class Pet has private fields petName, and petAge. Complete the derived class Dog, which extends the Pet class and includes a private field for dogBreed. Ex. If the input is: Dobby 2 Kreacher 3 German Schnauzer the output is: Pet Information: Name: Dobby Age: 2 Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

=+How might these stem from country and regional cultures?

Answered: 1 week ago