Computers and Technology

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());
}
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 21:00, ziahziah
Which function key is used to enable the spelling & grammar function in a word processing program such as microsoft word?
Answers: 3
image
Computers and Technology, 22.06.2019 11:30, stodd9503
Awell-diversified portfolio needs about 20-25 stocks from different categories is this true or false?
Answers: 2
image
Computers and Technology, 22.06.2019 20:00, hannahliebl2000
Need asap write a short paper describing the history and differences between six sigma, waterfall, agile, and scrum models. understanding these models can give you a good idea of how diverse and interesting it development projects can be. describe what the rationale for them is and describe their key features. describe the history behind their development. at least 400 words
Answers: 1
image
Computers and Technology, 23.06.2019 01:00, leo4687
Complete the sentence about a presentation delivery method
Answers: 2
Do you know the correct answer?
The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet cla...

Questions in other subjects:

Konu
Chemistry, 23.09.2019 00:00