subject

The cat store needs your help! The base class Animal has private fields animalName, and animalAge. The derived class Cat extends the Animal class and includes a private field for catBreed. Complete main() to: create a generic animal and print information using printInfo().
create a Cat animal, use printInfo() to print information, and add a statement to print the cat's breed using the getBreed() method.
Ex. If the input is:
Dobby
2
Kreacher
3
Maine Coon
the output is:
Pet Information:
Name: Dobby
Age: 2
Pet Information:
Name: Kreacher
Age: 3
Breed: Maine Coon
AnimalIformation. java
import java. util. Scanner;
public class AnimalInformation {
public static void main(String[] args) {
Scanner scnr = new Scanner(System. in);
Animal myAnimal = new Animal();
Cat myCat = new Cat();
String animalName, catName, catBreed;
int animalAge, catAge;
animalName = scnr. nextLine();
animalAge = scnr. nextInt();
scnr. nextLine();
catName = scnr. next();
catAge = scnr. nextInt();
scnr. nextLine();
catBreed = scnr. nextLine();
// TODO: Create generic animal (using animalName, animalAge) and then call printInfo
// TODO: Create cat animal (using catName, catAge, catBreed) and then call printInfo
// TODO: Use getBreed(), to output the breed of the cat
}
}
Animal. java
public class Animal {
protected String animalName;
protected int animalAge;
public void setName(String userName) {
animalName = userName;
}
public String getName() {
return animalName;
}
public void setAge(int userAge) {
animalAge = userAge;
}
public int getAge() {
return animalAge;
}
public void printInfo() {
System. out. println("Animal Information: ");
System. out. println(" Name: " + animalName);
System. out. println(" Age: " + animalAge);
}
}
Cat. java
public class Cat extends Animal {
private String catBreed;
public void setBreed(String userBreed) {
catBreed = userBreed;
}
public String getBreed() {
return catBreed;
}
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:30
Which of the following commands is more recommended while creating a bot?
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
Apart from confidential information, what other information does nda to outline? ndas not only outline confidential information, but they also enable you to outline .
Answers: 1
question
Computers and Technology, 24.06.2019 06:50
What are the things you are considering before uploading photos on social media?
Answers: 1
question
Computers and Technology, 24.06.2019 14:00
In simple terms, how would you define a protocol?
Answers: 2
You know the right answer?
The cat store needs your help! The base class Animal has private fields animalName, and animalAge. T...
Questions
question
Advanced Placement (AP), 01.01.2020 00:31
question
History, 01.01.2020 00:31