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, 22.06.2019 19:40
Solve the following javafx application: write a javafx application that analyzes a word. the user would type the word in a text field, and the application provides three buttons for the following: - one button, when clicked, displays the length of the word.- another button, when clicked, displays the number of vowels in the word.- another button, when clicked, displays the number of uppercase letters in the word(use the gridpane or hbox and vbox to organize the gui controls).
Answers: 1
question
Computers and Technology, 22.06.2019 21:30
Im doing this last minute and literally none of my neighbors or people that my dad works with use excel so if anyone could me make up an example
Answers: 1
question
Computers and Technology, 23.06.2019 20:00
Me ajude por favor , coloquei uma senha e não consigo tira-la no chorme
Answers: 2
question
Computers and Technology, 23.06.2019 23:30
What are "open-loop" and "closed-loop" systems
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
Social Studies, 06.05.2021 04:40
Questions on the website: 13722361