Question

Need help with this Java question in 1 hour please JAVA Using the files from the...

Need help with this Java question in 1 hour please

JAVA

Using the files from the in-class assignment add two additional animals of your choice. For each animal add two additional methods appropriate to your particular animal.

As the majority of the code for this program exists you will not need an algorithm. Use the 3 java classes below. Thank you

//Animal.java

public class Animal {

   public Animal() {

   System.out.println("A new animal has been created!");

   }

   public void sleep() {

   System.out.println("An animal sleeps...");

   }

     
   public void eat() {

   System.out.println("An animal eats...");

   }

   }

//Cat.java

public class Cat extends Animal {

   public Cat() {

   super();

   System.out.println("A new cat has been created!");

   }


   @Override

   public void sleep() {

   System.out.println("A cat sleeps...");

   }


   @Override

   public void eat() {

   System.out.println("A cat eats...");

   }

   }

//Bird.java

public class Bird extends Animal {

   public Bird() {

   super();

   System.out.println("A new bird has been created!");

   }

   @Override

   public void sleep() {

   System.out.println("A bird sleeps...");

   }


   @Override

   public void eat() {

   System.out.println("A bird eats...");

   }

   }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Animal.java

public class Animal {

   public Animal() {

   System.out.println("A new animal has been created!");

   }

   public void sleep() {

   System.out.println("An animal sleeps...");

   }

     
   public void eat() {

   System.out.println("An animal eats...");

   }

public void drink(){

System.out.println("An animal drinks...");

}

public void jumps() {

   System.out.println("A Horse Jumps...");

   }

   }

Adding 2 additional Animals : Dog and Horse with 2 new methods inherited from parent class Animals.

The 2 new methods are drink() and jumps() .

//Dog.java

public class Dog extends Animal {

   public Dog() {

   super();

   System.out.println("A new Dog has been created!");

   }

   @Override

   public void drink() {

   System.out.println("A Dog drinks..");

   }


   @Override

   public void jumps() {

   System.out.println("A Dog jumps..");

   }

   }

//Horse.java

public class Horse extends Animal {

   public Horse() {

   super();

   System.out.println("A new Horse has been created!");

   }

   @Override

   public void drink() {

   System.out.println("A Horse drinks...");

   }


   @Override

   public void jumps() {

   System.out.println("A Horse Jumps...");

   }

   }

Add a comment
Know the answer?
Add Answer to:
Need help with this Java question in 1 hour please JAVA Using the files from the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Add an animal (similar to cat) to the AnimalInheritance Example. class Animal { public Animal() {...

    Add an animal (similar to cat) to the AnimalInheritance Example. class Animal { public Animal() { System.out.println("A new animal has been created!"); } public void sleep() { System.out.println("An animal sleeps..."); } public void eat() { System.out.println("An animal eats..."); } } public class Cat extends Animal { public Cat() { super(); System.out.println("A new cat has been created!"); } public void sleep() { System.out.println("A cat sleeps..."); } public void purr() { System.out.println("A cat purrs..."); } public void eat() { System.out.println("An cat eats...");...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    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...

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are seven parts for one code, all are small code segments for one question. All the 'pets' need to 'speak', every sheet of code is connected. Four do need need any Debugging, three do have problems that need to be fixed. Does not need Debugging: public class Bird extends Pet { public Bird(String name) { super(name); } public void saySomething(){} } public class Cat...

  • This is the question about object-oriend programming(java) please show the detail comment and prefect code of...

    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 | |...

  • C# - Inheritance exercise I could not firgure out why my code was not working. I...

    C# - Inheritance exercise I could not firgure out why my code was not working. I was hoping someone could do it so i can see where i went wrong. STEP 1: Start a new C# Console Application project and rename its main class Program to ZooPark. Along with the ZooPark class, you need to create an Animal class. The ZooPark class is where you will create the animal objects and print out the details to the console. Add the...

  • What is wrong with the following Java Code. public class TestEdible { abstract class Animal {...

    What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...

  • Examples: Example 1-Runtime Polymorphism: Lets say we have a class Animal that has a method sound()....

    Examples: Example 1-Runtime Polymorphism: Lets say we have a class Animal that has a method sound(). Since this is a generic class so we can't give it a implementation like: Roar, Meow, Oink etc. We had to give a generic message public class Animal public void sound System.out.println("Animal is making a sound"); Now lets say we a subclass of Animal class. Horse that extends Animal class. We can provide the implementation to the same method like this: class Horse extends...

  • help with java OOP, here is the started code: package P2; public class Farm {   ...

    help with java OOP, here is the started code: package P2; public class Farm {    private double availableFood;    private Animal[] animals;    public Farm() {        setAvailableFood(1000);        animals = new Animal[4];        animals[0] = new Chicken();        animals[1] = new Cow();        animals[2] = new Llama();        animals[3] = new Llama();    }    public void makeNoise(){           // all animals make their sound (Moo, Cluck, etc)        for(Animal...

  • Java questions QUESTION 8 Assume the following classes are each defined in their own java files...

    Java questions QUESTION 8 Assume the following classes are each defined in their own java files and compile public class A public void display { System.out.println("A's display"); public class B extends A{ public void display { System.out.println("B's display"); public class C extends A public void display { System.out.println("C's display"); public class D { public static void main(String args) { 3: int i = ((int)(Moth.random(* 10)) if (i == 0) a = new BO: else if (i == 1) a =...

  • Java CSE 135 Which methods does the ChoiceQuestion class inherit from its superclass? Which methods does...

    Java CSE 135 Which methods does the ChoiceQuestion class inherit from its superclass? Which methods does it override? Which methods does it add? public class Question{ . . . public void display() { System.out.println(text); }} public class ChoiceQuestion extends Question{ . . . public void display() { super.display(); for (int i = 0; i < choices.size(); i++) { int choiceNumber = i + 1; System.out.println(choiceNumber + ": " + choices.get(i)); } }} public class QuestionDemo{ public static void main(String[] args)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT