Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming: Write an abstract class that represents an Animal. The class s

ID: 3772157 • Letter: J

Question

Java Programming:

Write an abstract class that represents an Animal. The class should have the following. Member variables to store the name of the animal and an integer to record the number of times people have visited the animal (should start at 0). A constructor to build objects of this class taking the animal name as an argument. A getter for the animal's name. A method named visit which takes no argument and increments the number of visitors the animal has had. A method named print Visited which takes no arguments and prints to the screen "X visitors have seen animal name . " Where X is the number of people who have visited. An abstract method named feed which takes no arguments.

Explanation / Answer

class Animal{
String name;
int count;
Animal(String n)
{
name=n;
count=0;
}
String getName(){
return name;
}
void visit(){
count++;
}
void printVisited(){
System.out.println(count + "visitors have seen animal name:" + name);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote