Question: 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 setName(String userName){
name = userName;
}
public String getName(){
return name;
}
public void setAge(int userAge){
age = userAge;
}
public int getAge(){
return age;
}
public void printInfo(){
System.out.println("Pet Information: ");
System.out.println(" Name: "+ name);
System.out.println(" Age: "+ age);
}
}
public static class Dog extends Pet {
private String breed;
public void setBreed(String userBreed){
breed = userBreed;
}
public String getBreed(){
return breed;
}
}
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
Pet myPet = new Pet();
Dog myDog = new Dog();
String petName, dogName, dogBreed;
int petAge, dogAge;
petName = scnr.nextLine();
petAge = scnr.nextInt();
scnr.nextLine(); // Consume the newline character
myPet.setName(petName);
myPet.setAge(petAge);
dogName = scnr.nextLine();
dogAge = scnr.nextInt();
scnr.nextLine(); // Consume the newline character
myDog.setName(dogName);
myDog.setAge(dogAge);
dogBreed = scnr.nextLine();
myDog.setBreed(dogBreed);
// 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());
}
}
 Fix the error import java.util.Scanner; public class PetInformation { public static

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!