Student will demonstrate the ability to utilize inheritance in a Java program. Student will demonstrate the ability to apply the IS A and HAS A relationships. Program Specifications: Start by watching Video Segment 16 from Dr. Colin Archibald's video series (found in the module overview).  Key in the program shown in the video and make sure it works. Then, add the following:

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

Java Assignment

Outcomes:

  • Student will demonstrate the ability to utilize inheritance in a Java program.
  • Student will demonstrate the ability to apply the IS A and HAS A relationships.

Program Specifications:

Start by watching Video Segment 16 from Dr. Colin Archibald's video series (found in the module overview).  Key in the program shown in the video and make sure it works.

Then, add the following:

  • Animals have a Weight.
  • Animals have a Height.
  • Dog is an Animal.
  • Dogs have a Name.
  • Dogs have a Breed.
  • Dogs have a DOB.
  • Cat is an Animal
  • Cats have a Name.
  • Cats have 9 lives, so you need to keep track of the remaining lives once a cat dies.
  • Bird is an Animal
  • Birds have a wing span
  • Birds have a canFly which is true or false (some birds cannot fly)
  • Create a test class that creates one of each type of animal and displays the animal’s toString method.

Submission Requirements:

  • You must follow the rules from the prior assignments. UMLs and Design Tools are not required for this one.

YOU MAY NOT EVER:

  • Use global variables.
  • Use the word goto.
  • Use the break command outside a case statement.

Java Code from the video:  

//TestInheritance.java

public class TestInheritance {

   public static void main(String[] args) {
      
       Animal myPet = new Animal(12);
       System.out.println(myPet);

       Dog max = new Dog (34, "MAX ");
       max.setName("Maxwell: ");
       max.setWeight(56);
      
       System.out.println(max);
   }

}

//end of Testinheritance.java

//Animal.java

public class Animal extends Object {

       private int weight;

  
       public Animal (int weight) {
           super();
           setWeight (weight);      
       }
       public int getWeight() {
           return weight;
       }
       public void setWeight(int weight) {
           this.weight = weight;
       }
       public String toString () {
           String result;
           result = "I'm an animal weighing: " + weight;
           return result;
       }
      
}

//End of Animal.java

//Dog.Java

public class Dog extends Animal {

   private String name;
  
   public Dog(int weight, String name) {
       super(weight);
       setName(name);      
   }  
   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }
   public String toString() {
       String result;
       result = "Dog: " + name + super.toString();
       return result;
   }
}

//End of Dog.java

Please tell me in which .java file the code you created goes into. Please be sure if you decide that you want me to replace my code with yours the data from the original stays and that I can simply paste it into eclipse. Thank You!

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 8 steps with 8 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr