Question
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
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 SchnauzerStep 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