Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Fix the error import java.util.Scanner; public class PetInformation { public static class Pet { protected String name; protected int age; public void setName ( String
Fix the error
import java.util.Scanner;
public class PetInformation
public static class Pet
protected String name;
protected int age;
public void setNameString userName
name userName;
public String getName
return name;
public void setAgeint userAge
age userAge;
public int getAge
return age;
public void printInfo
System.out.printlnPet Information: ;
System.out.println Name: name;
System.out.println Age: age;
public static class Dog extends Pet
private String breed;
public void setBreedString userBreed
breed userBreed;
public String getBreed
return breed;
public static void mainString args
Scanner scnr new ScannerSystemin;
Pet myPet new Pet;
Dog myDog new Dog;
String petName, dogName, dogBreed;
int petAge, dogAge;
petName scnrnextLine;
petAge scnrnextInt;
scnrnextLine; Consume the newline character
myPet.setNamepetName;
myPet.setAgepetAge;
dogName scnrnextLine;
dogAge scnrnextInt;
scnrnextLine; Consume the newline character
myDog.setNamedogName;
myDog.setAgedogAge;
dogBreed scnrnextLine;
myDog.setBreeddogBreed;
Create generic pet using petName, petAge and then call printInfo
myPet.printInfo;
System.out.println;
Create dog pet using dogName, dogAge, dogBreed and then call printInfo
myDog.printInfo;
Use getBreed to output the breed of the dog
System.out.println Breed: myDog.getBreed;
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