Java assignment.
/**************************Animal.java*******************************/
package animal;
public abstract class Animal {
private String name;
private String gender;
public Animal(String name, String gender) {
super();
this.name = name;
this.gender = gender;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public abstract void makeSound();
@Override
public String toString() {
return "Animal name: " + name + "
Gender: " + gender;
}
}
/********************************Dog.java**********************/
package animal;
public class Dog extends Animal {
private int levelOfMeanness;
public Dog(String name, String gender, int
levelOfMeanness) {
super(name, gender);
if (levelOfMeanness >= 1
&& levelOfMeanness <= 10)
this.levelOfMeanness = levelOfMeanness;
else {
levelOfMeanness = 1;
}
}
public int getLevelOfMeanness() {
return levelOfMeanness;
}
public void setLevelOfMeanness(int levelOfMeanness)
{
this.levelOfMeanness =
levelOfMeanness;
}
@Override
public void makeSound() {
System.out.println("Dog says
\"Bho-Bho\"");
}
@Override
public String toString() {
return super.toString() + " is a
Dog has level of meanness: " + levelOfMeanness;
}
}
/*******************************Cat.java************************/
package animal;
public class Cat extends Animal {
private int levelOfCuteness;
public Cat(String name, String gender, int
levelOfCuteness) {
super(name, gender);
if (levelOfCuteness >= 1
&& levelOfCuteness <= 10) {
this.levelOfCuteness = levelOfCuteness;
} else {
levelOfCuteness
= 1;
}
}
public int getLevelOfCuteness() {
return levelOfCuteness;
}
public void setLevelOfCuteness(int levelOfCuteness)
{
this.levelOfCuteness =
levelOfCuteness;
}
@Override
public void makeSound() {
System.out.println("Cat says \"Meow\"");
}
@Override
public String toString() {
return super.toString() + " is a
Cat has level of cuteness: " + levelOfCuteness;
}
}
/****************************Brindle.java************************/
package animal;
public class Brindle extends Dog {
private int numberOfStrips;
public Brindle(String name, String gender, int
levelOfMeanness, int numberOfStrips) {
super(name, gender,
levelOfMeanness);
this.numberOfStrips =
numberOfStrips;
}
public int getNumberOfStrips() {
return numberOfStrips;
}
public void setNumberOfStrips(int numberOfStrips)
{
this.numberOfStrips =
numberOfStrips;
}
@Override
public String toString() {
return super.toString() + " is a
Brindle Dog has level of meanness: " + getLevelOfMeanness() + " and
has "
+ numberOfStrips + " strips.";
}
}
/*******************************Driver.java******************/
package animal;
public class Driver {
public static void main(String[] args) {
Animal[] animals = new
Animal[4];
animals[0] = new Dog("Charlie",
"Male", 9);
animals[1] = new Cat("CuteCat",
"Female", 10);
animals[2] = new Brindle("Max",
"Male", 7, 30);
animals[3] = new
Cat("Sally","Female",9);
for (Animal animal : animals)
{
System.out.println(animal.toString());
animal.makeSound();
}
}
}
/*******************output******************/
Animal name: Charlie Gender: Male is a Dog has level of
meanness: 9
Dog says "Bho-Bho"
Animal name: CuteCat Gender: Female is a Cat has level of cuteness:
10
Cat says "Meow"
Animal name: Max Gender: Male is a Dog has level of meanness: 7 is
a Brindle Dog has level of meanness: 7 and has 30 strips.
Dog says "Bho-Bho"
Animal name: Sally Gender: Female is a Cat has level of cuteness:
9
Cat says "Meow"
Please let me know if you have any doubt or modify the answer, Thanks :)
Java assignment. There are five classes. You figure out the inheritance hierarchy. Animal, Dog, Brindle, Cat,...
Java Create four classes: 1. An Animal class that acts as a superclass for Dog and Bird 2. A Bird class that is a descendant of Animal 3. A Dog class that is a descendant of Animal 4. A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: · one instance variable, a private String variable named name · a single constructor that takes one argument, a String, used to set...
PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1. What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** * Program: PRG/421 Week 1 Analyze Assignment * Purpose: Analyze the coding for...
In Java please Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness. The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale: “ugliest dog ever!”...
Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness. The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale: “ugliest dog ever!” “pretty...
Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...
Create a base class and two derived classes. Also, create and call a member function named communicate() that behaves differently when called by each class. Create a single C++ project (and CPP source file) named animal_communication as follows: Into this source, type the source code for Program 15-16, "Program Output," in Section 15.6, "Polymorphism and Virtual Member Functions," in Ch. 15, "Inheritance, Polymorphism, and Virtual Functions," of Starting Out With C++ From Control Structures Through Objects. Run and debug the...
JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...
This is the question about object-oriend programming(java) please show the detail comment and prefect code of each class, Thank you! This question contain 7 parts(questions) Question 1 Create a class a class Cat with the following UML diagram: (the "-" means private , "+" means public) +-----------------------------------+ | Cat | +-----------------------------------+ | - name: String | | - weight: double | +-----------------------------------+ | + Cat(String name, double weight) | | + getName(): String | | + getWeight(): double | |...
In Exercise 1, displayAnimal uses an Animal reference variable as its parameter. Change your code to make the displayAnimal function anim parameter as an object variable, not a reference variable. Run the code and examine the output. What has changed? Polymorphic behavior is not possible when an object is passed by value. Even though printClassName is declared virtual, static binding still takes place because anim is not a reference variable or a pointer. Alternatively we could have used an Animal...
previous assignment code /*C++ test program to test the classes, Animal, Mammal and Cat and print the results on console window.*/ //Main.cpp //include header files #include<iostream> //include Animal, Mammal and Cat header files #include "Animal.h" #include "Mammal.h" #include "Cat.h" using namespace std; int main() { //create Animal object Animal animal("Dog","Mammal",4); cout<<"Animal object details"<<endl; cout<<"Name: "<<animal.getName()<<endl; cout<<"Type: "<<animal.getType()<<endl; cout<<"# of Legs: "<<animal.getLegs()<<endl; cout<<endl<<endl; //create Cat object Cat cat("byssinian cat","carnivorous mammal",4,"short...