Answered step by step
Verified Expert Solution
Link Copied!

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 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());
}
}
image text in transcribed

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

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

The company has fair promotion/advancement policies.

Answered: 1 week ago