Use Java and please try and show how to do each section.
You are creating a 'virtual pet' program. The pet object will have a number of attributes, representing the state of the pet. You will need to create some entity to represent attributes in general, and you will also need to create some specific attributes. You will then create a generic pet class (or interface) which has these specific attributes. Finally you will make at least one subclass of the pet class which will be a specific type of pet, and at least one instance of that class.
Attributes
An attribute is a characteristic of a pet. Each attribute is
essentially a list of values. For example, a hunger attribute may
have values from "famished" through "content" to "bloated." There
should be some way to check the value of the attribute, as well as
to increase and decrease the value. Note that you will be expected
to create some sort of abstract data type (ADT) to represent the
attribute. You are not yet building SPECIFIC attributes (like
hunger or happiness) but a type that represents the common
characteristics of all attributes. You might use an interface or an
abstract class to generate your abstraction, but plan it first as
an abstract data type.
Specific Attributes
Once you have created a generic attribute class, make some
subclasses to represent the specific attributes you want your pets
to have. If you designed the ADT well, creating specific subclasses
should be quite easy. The main method of the specific classes
should test the main functionality of the class.
Making your abstract pet
Now create a pet class that uses the attributes you have generated.
This class is also abstract, as it represents just a type of pet.
It will include attributes as data members, and it may also have
other characteristics. You may also add methods that indicate
actions the user can take with the pet, including things like feed
and play (which may affect attributes) and perhaps other activities
like rename (which might change another data member of the pet) and
sleep (which might indicate the passage of time.)
Build a specific pet class
Finally you should be able to build a specific type of pet (like a
lizard or a unicorn) that inherits from the pet class. This should
begin (of course) with characteristics derived from the abstract
pet, but you could then add new attributes or behaviors specific to
your type of pet.
The main method of this pet class should instantiate an instance of the pet and indicate all the things it can do.
Create an interface for interacting with the pet.
Build some type of tool for interacting with the pet. At minimum
this should allow the user to create a pet, interact with it in the
ways you have defined, save its current status for future play
(using object serialization) and load a previously saved pet.
package InheritanceAbstract;
// Abstract class defined
abstract class Pet
{
// Instance variable to store pet data
String name;
String color;
// Parameterized constructor to assign
// parameter data to instance variable
Pet(String na, String co)
{
name = na;
color = co;
}// End of parameterized constructor
// Overrides toString() method to return pet information
public String toString()
{
return "\n Name: " + name + "\n Color: " + color;
}// End of method
// Abstract method
abstract String canDo();
abstract String sound();
}// End of abstract class Pet
// Defines a class Cat derived from Pet class
class Cat extends Pet
{
// Instance variable to store pet data
boolean available;
// Parameterized constructor to assign
// parameter data to instance variable
Cat(String na, String co, boolean av)
{
super(na, co);
available = av;
}// End of parameterized constructor
// Overrides method to return cat sound
public String sound()
{
return "Miauw";
}// End of method
// Overrides the method to return what can can do
String canDo()
{
// Checks if cat is available then returns "Dance"
if(available)
return "Dance.";
// Otherwise not available returns "Kill rat."
else
return "Kill rat.";
}// End of method
// Overrides toString() method to return pet information
public String toString()
{
String res = "";
// Checks if available then assign message "Available"
if(available)
res = "Available";
// Otherwise not available assign message "Not Available"
else
res = "Not available";
// Calls the base class toString() method
// and concatenates available status
return super.toString() + "\n Available Status: " + res;
}// End of method
}// End of class Cat
// Defines a class Dog derived from Pet class
class Dog extends Pet
{
// Instance variable to store pet data
String breed;
// Parameterized constructor to assign
// parameter data to instance variable
Dog(String na, String co, String br)
{
super(na, co);
breed = br;
}// End of parameterized constructor
// Overrides method to return cat sound
public String sound()
{
return "Woof";
}// End of method
// Overrides the method to return what can can do
String canDo()
{
// Checks if breed is "pamorian" then returns "Play cricket."
if(breed.compareToIgnoreCase("pamorian") == 0)
return "Play cricket.";
// Otherwise checks if breed is "dogerman" then returns "Swim."
else if(breed.compareToIgnoreCase("dogerman") == 0)
return "Swim.";
// Otherwise returns "Dance"
else
return "Dance.";
}// End of method
// Overrides toString() method to return pet information
public String toString()
{
return super.toString() + "\n Breed: " + breed;
}// End of method
}// End of class Dog
// Driver class definition
public class AnimalTest
{
// main method definition
public static void main(String ss[])
{
// Declares an array of object of class Pet of size 4
Pet myPet[] = new Pet[4];
// Creates two cats using parameterized constructor
myPet[0] = new Cat("Pusy", "white", true);
myPet[1] = new Cat("Buly", "black", false);
// Creates two dogs using parameterized constructor
myPet[2] = new Dog("Stalin", "brown", "pamorian");
myPet[3] = new Dog("Banodi", "white", "dogerman");
// Loops till number of Pets
for(Pet pp : myPet)
{
// Displays information
System.out.println(pp);
System.out.println(" My pet sounds: " + pp.sound());
System.out.println(" My pet can: " + pp.canDo());
}// End of for loop
}// End of main method
}// End of driver class
Sample Output:
Name: Pusy
Color: white
Available Status: Available
My pet sounds: Miauw
My pet can: Dance.
Name: Buly
Color: black
Available Status: Not available
My pet sounds: Miauw
My pet can: Kill rat.
Name: Stalin
Color: brown
Breed: pamorian
My pet sounds: Woof
My pet can: Play cricket.
Name: Banodi
Color: white
Breed: dogerman
My pet sounds: Woof
My pet can: Swim.
Use Java and please try and show how to do each section. You are creating a 'virtual pet' program...
Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...
(The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...
Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...
Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...
Program in Java: Use the Factory pattern to address the following challenge... Your job is to make it easy to obtain a Pet from a factory-like class: ● Pet is an abstract class that has 2 attributes ○ Name ○ Sound ● You should create 3 concrete types of pets ○ Parakeet (makes the sound "Tweet tweet") ○ Dog (makes the sound "Woof woof") ○ Lion (makes the sound "Roar roar") ● You should create a factory class that allows...
Can someone help me in java Net Beans IDE witht the code and java comments. ThanksMany of these classes will just need to be copied from previous assignments. When you implement the Tree interface you may import the java.util.Iterator class. When you implement the AbstractBinaryTree class you may import the java.util.ArrayList class and the java.util.List class.In this project you will be doing the following:Create a NetBeans project named lab07 and ensure it is imported into your SVN.In this lab assignment...
I am having trouble with this assignment. Please help. For this assignment, you will select either the Cat or Dog Java class from the UML diagram provided in Project One and implement it. Open the Virtual Lab by clicking on the link in the Virtual Lab Access module. Then open your IDE and create a new class. Use the Eclipse IDE and Downloading Files From Eclipse tutorials to help you with this project. Review the UML Class Diagram, paying special...
********************Java Assigment******************************* 1. The following interface and classes have to do with the storage of information that may appear on a mailing label. Design and implement each of the described classes below. public interface AddrLabelInterface { String getAttnName(); String getTitle(); // Mr., Mrs., etc. String getName(); String getNameSuffix(); // e.g., Jr., III String getProfessionalSuffix(); // O.D. (doctor of optometry) String getStreet(); String getSuiteNum(); String getCity(); String getState(); String getZipCode(); } Step 1 Create an abstract AddrLabel class that implements the...
In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...
*****************************In Java***************************************In Java***********************************In Java************************* In this problem, you will implement various algorithms operating on binary search trees. We have provided with you a standard implementation of a generic BST in BinarySearchTree.java. Note that this class is an abstract class, which means that some of its methods are not implemented. In previous assignments, you have implemented interfaces which specified methods that you needed to write. Very similarly, an abstract class is a class with some unimplemented methods (it can be thought...