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:
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!
Trending now
This is a popular solution!
Step by step
Solved in 8 steps with 8 images