subject

The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet class and includes a private field for dogBreed. Complete main() to: create a generic pet and print information using printInfo().
create a Dog pet, use printInfo() to print information, and add a statement to print the dog's breed using the getBreed() method.
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
(File is marked as read-only)
Dog. java
public class Dog extends Pet {
private String dogBreed;
public void setBreed(String userBreed) {
dogBreed = userBreed;
}
public String getBreed() {
return dogBreed;
}
}
(File is marked as read-only)
Pet. java
public class Pet {
protected String petName;
protected int petAge;
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);
}
}
PetInformation. java
import java. util. Scanner;
public class PetInformation {
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();
dogName = scnr. next();
dogAge = scnr. nextInt();
scnr. nextLine();
dogBreed = scnr. nextLine();
// TODO: Create generic pet (using petName, petAge) and then call printInfo
myPet. setPetName(petName);
myPet. setPetAge(petAge);
myPet. printInfo();
// TODO: Create dog pet (using dogName, dogAge, dogBreed) and then call printInfo
myDog. setPetName(dogName);
myDog. setPetAge(dogAge);
myDog. setDogBreed(dogBreed);
myDog. printInfo();
// TODO: Use getBreed(), to output the breed of the dog
System. out. println(" Breed: " + myDog. getDogBreed());
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 23:00
In a file-oriented information system, a work file stores relatively permanent data about an entity is created and saved for backup and recovery purposes stores records that contain day-to-day business and operational data is a temporary file created by an information system for a single task
Answers: 1
question
Computers and Technology, 22.06.2019 11:50
You have written, as part of a school assignment, a research paper on the solar system. you want to share this paper on your school website. on which type of server will you upload it?
Answers: 1
question
Computers and Technology, 22.06.2019 20:00
Which location-sharing service offers items for users as a gaming component and also allows them to collectively link their check-ins to publish a trip? a. whrrl b. buzzd c. foursquare (this option is wrong i already tried) d. gowalla for plato
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
Light travels at a speed of 186,000 miles a second. the distance light travels in a year is 5,865,690,000,000 miles/year 5,865,695,000,000 miles/year 58,656,950,000,000 miles/year 6,789,000,0000 miles/year
Answers: 1
You know the right answer?
The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet cla...
Questions
question
Mathematics, 26.02.2021 18:00
question
Mathematics, 26.02.2021 18:00
question
Mathematics, 26.02.2021 18:00
question
Mathematics, 26.02.2021 18:00
question
Biology, 26.02.2021 18:00
question
English, 26.02.2021 18:00
Questions on the website: 13722367