Question

In: Computer Science

Make Animal an abstract class. Create a Kennel Class Create 2-3 Dog objects Create 2-3 Cat...

Make Animal an abstract class.

  • Create a Kennel Class
    • Create 2-3 Dog objects
    • Create 2-3 Cat objects
  • Put your Dog and Cat objects in an Array of Animals
  • Loop over your Animals and print the animal with Species, Age, and the status of the appropriate vaccines.

Using the code below:

public class Animal {
    //Declaring instance variables
    private int age;
    private boolean RabiesVaccinationStatus;
    private String name;
    private String ownerName;

    //Zero argumented constructor
    public Animal() {

    }
    //Parameterized constructor
    public Animal(int age, boolean rabiesVaccinationStatus, String name,
                  String ownerName) {
        this.age = age;
        RabiesVaccinationStatus = rabiesVaccinationStatus;
        this.name = name;
        this.ownerName = ownerName;
    }

    // getters and setters
    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isRabiesVaccinationStatus() {
        return RabiesVaccinationStatus;
    }

    public void setRabiesVaccinationStatus(boolean rabiesVaccinationStatus) {
        RabiesVaccinationStatus = rabiesVaccinationStatus;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOwnerName() {
        return ownerName;
    }

    public void setOwnerName(String ownerName) {
        this.ownerName = ownerName;
    }

    //toString method is used to display the contents of an object inside it
    public String toString() {
        return "Age :" + age + ", Rabies Vaccination Status :"
                + RabiesVaccinationStatus + ", Name :" + name
                + ", Owner Name :" + ownerName;
    }

}


// Dog.java

class Dog extends Animal {
    //Declaring instance variables
    private boolean distemperVaccinationStatus;

    //Parameterized constructor
    public Dog(boolean distemperVaccinationStatus) {
        this.distemperVaccinationStatus = distemperVaccinationStatus;
    }

    //Parameterized constructor
    public Dog(int age, boolean rabiesVaccinationStatus, String name,
               String ownerName, boolean distemperVaccinationStatus) {
        super(age, rabiesVaccinationStatus, name, ownerName);
        this.distemperVaccinationStatus = distemperVaccinationStatus;
    }

    // getters and setters
    public boolean isDistemperVaccinationStatus() {
        return distemperVaccinationStatus;
    }

    public void setDistemperVaccinationStatus(boolean distemperVaccinationStatus) {
        this.distemperVaccinationStatus = distemperVaccinationStatus;
    }

    //toString method is used to display the contents of an object inside it
    public String toString() {
        return "Dog :"+super.toString() + " Distemper Vaccination Status :"
                + distemperVaccinationStatus;
    }

    public void speak()
    {
        System.out.println("bark");
    }

}

// Cat,.java

class Cat extends Animal {
    //Declaring instance variables
    private boolean felineLeukemiaVaccinationStatus;
    private boolean declawedStatus;

    //Parameterized constructor
    public Cat(boolean felineLeukemiaVaccinationStatus, boolean declawedStatus) {
        this.felineLeukemiaVaccinationStatus = felineLeukemiaVaccinationStatus;
        this.declawedStatus = declawedStatus;
    }
    //Parameterized constructor
    public Cat(int age, boolean rabiesVaccinationStatus, String name,
               String ownerName, boolean felineLeukemiaVaccinationStatus,
               boolean declawedStatus) {
        super(age, rabiesVaccinationStatus, name, ownerName);
        this.felineLeukemiaVaccinationStatus = felineLeukemiaVaccinationStatus;
        this.declawedStatus = declawedStatus;
    }

    // getters and setters
    public boolean isFelineLeukemiaVaccinationStatus() {
        return felineLeukemiaVaccinationStatus;
    }

    public void setFelineLeukemiaVaccinationStatus(
            boolean felineLeukemiaVaccinationStatus) {
        this.felineLeukemiaVaccinationStatus = felineLeukemiaVaccinationStatus;
    }

    public boolean isDeclawedStatus() {
        return declawedStatus;
    }

    public void setDeclawedStatus(boolean declawedStatus) {
        this.declawedStatus = declawedStatus;
    }

    //toString method is used to display the contents of an object inside it
    public String toString() {
        return "Cat :"+super.toString() + " Feline Leukemia Vaccination Status :"
                + felineLeukemiaVaccinationStatus + ", Declawed Status :"
                + declawedStatus;
    }

    public void speak()
    {
        System.out.println("Meow");
    }

}

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________


// Animal.java

public abstract class Animal {
   //Declaring instance variables
   private int age;
   private boolean RabiesVaccinationStatus;
   private String name;
   private String ownerName;

   //Zero argumented constructor
   public Animal() {

   }
   //Parameterized constructor
   public Animal(int age, boolean rabiesVaccinationStatus, String name,
   String ownerName) {
   this.age = age;
   RabiesVaccinationStatus = rabiesVaccinationStatus;
   this.name = name;
   this.ownerName = ownerName;
   }

   // getters and setters
   public int getAge() {
   return age;
   }

   public void setAge(int age) {
   this.age = age;
   }

   public boolean isRabiesVaccinationStatus() {
   return RabiesVaccinationStatus;
   }

   public void setRabiesVaccinationStatus(boolean rabiesVaccinationStatus) {
   RabiesVaccinationStatus = rabiesVaccinationStatus;
   }

   public String getName() {
   return name;
   }

   public void setName(String name) {
   this.name = name;
   }

   public String getOwnerName() {
   return ownerName;
   }

   public void setOwnerName(String ownerName) {
   this.ownerName = ownerName;
   }

   //toString method is used to display the contents of an object inside it
   public String toString() {
   return "Age :" + age + ", Rabies Vaccination Status :"
   + RabiesVaccinationStatus + ", Name :" + name
   + ", Owner Name :" + ownerName;
   }
   public abstract void speak();
  
   }

___________________________

// Cat.java

public class Cat extends Animal {
//Declaring instance variables
private boolean felineLeukemiaVaccinationStatus;
private boolean declawedStatus;

//Parameterized constructor
public Cat(boolean felineLeukemiaVaccinationStatus, boolean declawedStatus) {
this.felineLeukemiaVaccinationStatus = felineLeukemiaVaccinationStatus;
this.declawedStatus = declawedStatus;
}
//Parameterized constructor
public Cat(int age, boolean rabiesVaccinationStatus, String name,
String ownerName, boolean felineLeukemiaVaccinationStatus,
boolean declawedStatus) {
super(age, rabiesVaccinationStatus, name, ownerName);
this.felineLeukemiaVaccinationStatus = felineLeukemiaVaccinationStatus;
this.declawedStatus = declawedStatus;
}

// getters and setters
public boolean isFelineLeukemiaVaccinationStatus() {
return felineLeukemiaVaccinationStatus;
}

public void setFelineLeukemiaVaccinationStatus(
boolean felineLeukemiaVaccinationStatus) {
this.felineLeukemiaVaccinationStatus = felineLeukemiaVaccinationStatus;
}

public boolean isDeclawedStatus() {
return declawedStatus;
}

public void setDeclawedStatus(boolean declawedStatus) {
this.declawedStatus = declawedStatus;
}

//toString method is used to display the contents of an object inside it
public String toString() {
return "Cat :"+super.toString() + " Feline Leukemia Vaccination Status :"
+ felineLeukemiaVaccinationStatus + ", Declawed Status :"
+ declawedStatus;
}

public void speak()
{
System.out.println("Meow");
}

}
___________________________

// Dog.java

public class Dog extends Animal {
//Declaring instance variables
private boolean distemperVaccinationStatus;

//Parameterized constructor
public Dog(boolean distemperVaccinationStatus) {
this.distemperVaccinationStatus = distemperVaccinationStatus;
}

//Parameterized constructor
public Dog(int age, boolean rabiesVaccinationStatus, String name,
String ownerName, boolean distemperVaccinationStatus) {
super(age, rabiesVaccinationStatus, name, ownerName);
this.distemperVaccinationStatus = distemperVaccinationStatus;
}

// getters and setters
public boolean isDistemperVaccinationStatus() {
return distemperVaccinationStatus;
}

public void setDistemperVaccinationStatus(boolean distemperVaccinationStatus) {
this.distemperVaccinationStatus = distemperVaccinationStatus;
}

//toString method is used to display the contents of an object inside it
public String toString() {
return "Dog :"+super.toString() + " Distemper Vaccination Status :"
+ distemperVaccinationStatus;
}

public void speak()
{
System.out.println("bark");
}

}

_________________________

// Kennel.java

public class Kennel {

   public static void main(String[] args) {
Animal animals[]={new Dog(2,true,"Max","Ricky",true),
       new Dog(3,true,"Leo","Mike",true),
       new Dog(3,true,"Coffee","Sachin",false),
       new Cat(2,true,"Kitty","Rahul",true,true),
       new Cat(1,false,"Honey","Micheal",true,false),
       new Cat(1,false,"Mitty","Bobby",true,true)};
  
for(int i=0;i<animals.length;i++)
{
   System.out.println(animals[i]);
}

   }

}
__________________________

Output:

Dog :Age :2, Rabies Vaccination Status :true, Name :Max, Owner Name :Ricky Distemper Vaccination Status :true
Dog :Age :3, Rabies Vaccination Status :true, Name :Leo, Owner Name :Mike Distemper Vaccination Status :true
Dog :Age :3, Rabies Vaccination Status :true, Name :Coffee, Owner Name :Sachin Distemper Vaccination Status :false
Cat :Age :2, Rabies Vaccination Status :true, Name :Kitty, Owner Name :Rahul Feline Leukemia Vaccination Status :true, Declawed Status :true
Cat :Age :1, Rabies Vaccination Status :false, Name :Honey, Owner Name :Micheal Feline Leukemia Vaccination Status :true, Declawed Status :false
Cat :Age :1, Rabies Vaccination Status :false, Name :Mitty, Owner Name :Bobby Feline Leukemia Vaccination Status :true, Declawed Status :true

_______________Could you plz rate me well.Thank You


Related Solutions

Create a java class with name Cat. Instructions for Cat class: This class is modeled after...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after a Cat. You should have instance variables as follows: The Cat’s name The number of mice caught by the Cat. Whether or not the Cat is secretly plotting to kill you Note that you will need to choose both good types and meaningful identifiers for each of these instance variables. You may also assume that the Cat is not automatically always secretly plotting to...
Java assignment, abstract class, inheritance, and polymorphism. these are the following following classes: Animal (abstract) Has...
Java assignment, abstract class, inheritance, and polymorphism. these are the following following classes: Animal (abstract) Has a name property (string) Has a speech property (string) Has a constructor that takes two arguments, the name and the speech It has getSpeech() and setSpeech(speech) It has getName and setName(name) It has a method speak() that prints the name of the animal and the speech. o Example output: Tom says meow. Mouse Inherits the Animal class Has a constructor takes a name and...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
In java: -Create a class named Animal
In java: -Create a class named Animal
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel....
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel. A dog consists of the following information: • An integer age. • A string name. If the given name contains non-alphabetic characters, initialize to Wolfy. • A string bark representing the vocalization the dog makes when they ‘speak’. • A boolean representing hair length; true indicates short hair. • A float weight representing the dog’s weight (in pounds). • An enumeration representing the type...
Animal class Create a simple class called Animal instantiated with a name and a method toString...
Animal class Create a simple class called Animal instantiated with a name and a method toString which returns the name. Cat class Create a simple class Cat which extends Animal, but adds no new instance variable or methods. RedCat class Create a simple class RedCat which extends Cat, but adds no new instance variable or methods. WildCardTester class Create a class with the main method and methods addCat, deleteCat and printAll as follows. addCat method Has two parameters, an ArrayList...
In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class....
In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class. The vehicle class should contain at least 2 variables that could pertain to ANY vehicle and two methods. The truck class should contain 2 variables that only apply to trucks and one method. Create a console program that will instantiate a truck with provided member information then call one method from the truck and one method contained from the inherited vehicle class. Have these...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance of Dog and use its methods. Purpose: This application provides experience with creating classes and instances of objects in C#. Requirements: Project Name: Dog Target Platform: Console Programming Language: C# Documentation: Types and variables (Links to an external site.) (Microsoft) Classes and objects (Links to an external site.) (Microsoft) Enums (Links to an external site.) (Microsoft) Create a class called Dog. Dog is to...
Which animal has the least extensive uterine horns Pig Cat Dog Horse Lipase from the pancreas,...
Which animal has the least extensive uterine horns Pig Cat Dog Horse Lipase from the pancreas, is necessary for the digestion of lipids True False A gallbladder is necessary for lipid digestion True False Which is not associated with the monogastric stomach Microvilli Three layers of muscularis Rugae Crypts The streak canal connects the alveoli to the gland cistern True False A disorder affecting the functionality of mucous cells may result in Increased peristalsis Ulceration of the gastric mucosa Decreased...
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return...
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemCost. Derive a class BulkDiscount from DiscountPolicy. It should have a constructor that has two parameters minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more then minimum, the discount is percent percent.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT