Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Refer to the Powerpoint diagram: Change the given code as follows: Add height, weight to Animal add these as doubles to class Animal ( where
Refer to the Powerpoint diagram: Change the given code as follows:
Add height, weight to Animal
add these as doubles to class Animal where are declared
add appropriate assignments in Animal constructor for height and weight like it does for
add height and weight to super statement in Mammal constructor
add height and weight to super statements in Cat and Kangaroo constructor
add height and weight parameters to animals boots whiskers.. createddeclared in main
Add toString to Animal
add a toString method to the Animal class that returns a string with the following:
name
height
weight
location formatted to decimal places
the toString method should look like:
@override
public string tostring
return somestring;
the string returned should look like:
Boots Weighs: Height: is now at:
The toString method should not print anything
For each species object in mainboots whiskers, kanga call its toString method:
once before the MoveAnAnimal for loop section in main:
once after the VocalizeAnAnimal section in main:
Using Cat or Kangaroo class as your template, add a species class Platypus, with the following:
reproduction type MONOTREME
when it vocalizes it "snuffles"
in its move method it walks or swims
use a random number so that it walks half the time and swims the other half
it uses feet whether walking or swimming
if it swims it moves half as far as it does walking
Create a Platypus class object in the AnimalKingdom class called "platty" and use it as the other
species have done:
Create it in main as the others have it should have name, height, weight..
Call its toString method where the others have
Call MoveAnAnimal where the others have
Call VocalizeAnAnimal where the others have
Call its toString method again where the others have
AnimalKingdomObjectDiagram.ppt
Use the given code in:
AnimalKingdom.java
The Animal class is abstract and has Mammal class as a derived class.
The Mammal class is abstract and has Animal as its base or super class
The classes derived from Mammal are "species" classes such as Cat and Kangaroo. Note, there is no "species" class
in this assignment. The term "species" here is only used to refer to classes derived from the Mammal class.
The AnimalKingdom class instantiates and exercises the above classes
The MoveAnAnimal method takes an Animal object and moves it a random distance
The VocalizeAnAnimal method takes an Animal object and calls its vocalize method
There are sections in main:
In the first section Cat and Kangaroo objects are created with name whiskers "kanga"
The MoveAnAnimal section has a loop that moves each of the animals times
The VocalizeAnAnimal section exercises the vocalize method of each animal
You will add members and methods to the abstract class Animal as well as create another species and exercise it
accordingly. This program shows how abstract classes are used and how inheritance and polymorphism works. You
should develop this code incrementally changing one thing at a time and getting it to work and then move on to the
next thing. Do these changes in the order listed.
Java code all together
package com.animalkingdom;
import java.util.Random;
Animal class
abstract class Animal
protected String name;
protected double x;
protected double y;
Animal constructor
public AnimalString name
this.name name;
this.x ;
this.y ;
abstract void vocalize;
abstract void movedouble x double y;
abstract void eat;
Mammal class
Mammal class inherits from Animal
abstract class Mammal extends Animal
enum REPRODUCTIONTYPE MARSUPIAL PLACENTAL, MONOTREME;
protected REPRODUCTIONTYPE reproductionType;
public MammalString name, REPRODUCTIONTYPE reproductionType
supername;
this.reproductionType reproductionType;
@Override
public void vocalize
System.out.printlnMammal: name is vocalizing.";
@Override
void movedouble x double y
double oldxthis.x oldythis.y;
this.x x;
this.y y;
System.out.printfMammal: s is moving was at: f f is now at: f f
name, oldx, oldy, this.x this.y;
a species class inherits from Mammal, this is a concrete class
class Cat extends Mammal
public CatString name
supername Mammal.REPRODUCTIONTYPE.PLACENTAL;
@Override
public void vocalize
System.out.printlnname says meow!";
@Override
public void moved
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started