Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective: IT\'S A JAVA PROGRAMMING ASSIGNMENT To give you practice creating and

ID: 3710402 • Letter: O

Question

Objective: IT'S A JAVA PROGRAMMING ASSIGNMENT To give you practice creating and working with classes and derivation The Program: Dinosaurs have several basic characteristics: a species name, height and weight, movement speed, and diet. They also have several basic behaviors: eating, moving, and sleeping Your assignment is to define and implement a generic Dinosaur class that defines these characteristics and behaviors. The behaviors can be very basic, just printing out a line saying something like "sleeps." Declare all member fields as private, and make sure that you have accessor functions for all of the member fields. Use the Dinosaur class as a base class and make classes to represent the following: * - * Apatosaurus (a very large, herbivorous, slow-moving dinosaur) Tyrannosaurus Rex (a large, carnivorous, fast dinosaur) Hadrosaur (a medium-sized, herbivorous, fast dinosaur) For each of these classes, come up with at least two additional pieces of information about that specific dinosaur type (eg, for a Tyrannosaurus, you might have the number of teeth the particular Tyrannosaur has). Also, customize at least one of the sleeping/eating/moving behaviors for each class as appropriate. You can make up any details you want if you don't want to bother looking up information about dinosaurs Once you have these classes, write a small driver program that: Creates one of each kind of dinosaur object Have each one go through its behaviors -

Explanation / Answer

package Shapes;

public class Dinosaur {

private String moving;

private String eating;

private String type;

/**

* @return the moving

*/

public String getMoving() {

return moving;

}

/**

* @param moving the moving to set

*/

public void setMoving(String moving) {

this.moving = moving;

}

/**

* @return the eating

*/

public String getEating() {

return eating;

}

/**

* @param eating the eating to set

*/

public void setEating(String eating) {

this.eating = eating;

}

/**

* @return the type

*/

public String getType() {

return type;

}

/**

* @param type the type to set

*/

public void setType(String type) {

this.type = type;

}

public Dinosaur(String moving, String eating, String type) {

super();

this.moving = moving;

this.eating = eating;

this.type = type;

}

/* (non-Javadoc)

* @see java.lang.Object#toString()

*/

@Override

public String toString() {

return "Dinosaur [moving=" + moving + ", eating=" + eating + ", type="

+ type + "]";

}

public String displayInfo(){

return this.toString();

}

}

package Shapes;

public class Apatosaurs extends Dinosaur{

private String moving;

private String eating;

private String type;

private String sleeping;

/**

* @return the moving

*/

public String getMoving() {

return moving;

}

/**

* @param moving the moving to set

*/

public void setMoving(String moving) {

this.moving = moving;

}

/**

* @return the eating

*/

public String getEating() {

return eating;

}

/**

* @param eating the eating to set

*/

public void setEating(String eating) {

this.eating = eating;

}

/**

* @return the type

*/

public String getType() {

return type;

}

/**

* @param type the type to set

*/

public void setType(String type) {

this.type = type;

}

/**

* @return the sleeping

*/

public String getSleeping() {

return sleeping;

}

/**

* @param sleeping the sleeping to set

*/

public void setSleeping(String sleeping) {

this.sleeping = sleeping;

}

public Apatosaurs(String moving, String eating, String type, String sleeping) {

super(sleeping, sleeping, sleeping);

this.sleeping = sleeping;

}

public String displayInfo(){

return toString()+ "SleepingTime :"+this.sleeping;

}

}

3)

package Shapes;

public class Tyranosourus extends Dinosaur{

private String moving;

private String eating;

private String type;

private String size;

public Tyranosourus(String moving, String eating, String type,String size) {

super(moving, eating, type);

// TODO Auto-generated constructor stub

this.size=size;

}

/**

* @return the moving

*/

public String getMoving() {

return moving;

}

/**

* @param moving the moving to set

*/

public void setMoving(String moving) {

this.moving = moving;

}

/**

* @return the eating

*/

public String getEating() {

return eating;

}

/**

* @param eating the eating to set

*/

public void setEating(String eating) {

this.eating = eating;

}

/**

* @return the type

*/

public String getType() {

return type;

}

/**

* @param type the type to set

*/

public void setType(String type) {

this.type = type;

}

/**

* @return the size

*/

public String getSize() {

return size;

}

/**

* @param size the size to set

*/

public void setSize(String size) {

this.size = size;

}

public String displayInfo(){

return toString()+ "size :"+this.size;

}

}

4)

package Shapes;

public class Hadrasaur extends Dinosaur{

private String moving;

private String eating;

private String type;

private String size;

public Hadrasaur(String moving, String eating, String type,String size) {

super(moving, eating, type);

// TODO Auto-generated constructor stub

this.size=size;

}

/**

* @return the moving

*/

public String getMoving() {

return moving;

}

/**

* @param moving the moving to set

*/

public void setMoving(String moving) {

this.moving = moving;

}

/**

* @return the eating

*/

public String getEating() {

return eating;

}

/**

* @param eating the eating to set

*/

public void setEating(String eating) {

this.eating = eating;

}

/**

* @return the type

*/

public String getType() {

return type;

}

/**

* @param type the type to set

*/

public void setType(String type) {

this.type = type;

}

/**

* @return the size

*/

public String getSize() {

return size;

}

/**

* @param size the size to set

*/

public void setSize(String size) {

this.size = size;

}

public String displayInfo(){

return toString()+ "size :"+this.size;

}

}

5)

package Shapes;

public class DinosaurTest {

public static void main(String[] args) {

Apatosaurs a = new Apatosaurs("slow moving", "Plant", "herbivorous", "eight hours");

Tyranosourus t = new Tyranosourus("fast", "Animals ", "CArniviours", "10 feet");

Hadrasaur h = new Hadrasaur("slow", "Plant tree", "herbivorous", "medium sized");

System.out.println(a.displayInfo());

System.out.println(t.displayInfo());

System.out.println(h.displayInfo());

}

}

OUTPUT :

Dinosaur [moving=eight hours, eating=eight hours, type=eight hours]SleepingTime :eight hours

Dinosaur [moving=fast, eating=Animals , type=CArniviours]size :10 feet

Dinosaur [moving=slow, eating=Plant tree, type=herbivorous]size :medium sized