Griffin.java

  1. package edu.nwmissouri.animalList;

  2. import java.util.Scanner;

  3. enum NumberParity {
  4.     EVEN,
  5.     ODD
  6. }

  7. /**
  8.  * The class Griffin, a subclass of Animal
  9.  *
  10.  * @author Alexander Dieringer
  11.  */
  12. public class Griffin extends Animal {

  13.     /**
  14.      * Define variables to hold data about the Griffin class May refactor
  15.      * variables into super class To be used in additional methods added later
  16.      */
  17.     private final String species_name;
  18.     private final String species_latin;
  19.     private final String locationFound;
  20.     private final int sleepDuration_hours;
  21.     private final int movementSpeed_mph;
  22.     private final boolean isExtinct;

  23.     /**
  24.      * Griffin constructor Creates an instance of the Griffin class, requires a
  25.      * name
  26.      *
  27.      * @param name The name we will be giving our new Griffin
  28.      */
  29.     public Griffin(String name) {
  30.         super(name);

  31.         this.species_name = "Griffin";
  32.         this.species_latin = "grČ³pus";
  33.         this.locationFound = "Fantasy";
  34.         this.sleepDuration_hours = 8;
  35.         this.movementSpeed_mph = 80;
  36.         this.isExtinct = true;
  37.     }

  38.     /******************************
  39.      * SUPERCLASS FUNCTION OVERRIDES
  40.      *******/
  41.    
  42.    
  43.     /**
  44.      * speak() - Presents the types of sounds made by the Griffin
  45.      */
  46.     @Override
  47.     public void speak() {
  48.         System.out.println("I'm a Griffin and I chirp like a bird, but I can "
  49.                 + "trumpet loudly if angry.");
  50.     }

  51.     /**
  52.      * move() - Describes the general type of movement the animal Griffin
  53.      */
  54.     @Override
  55.     public void move() {
  56.         System.out.println("I can walk but I really enjoy flying through the sky.");
  57.     }

  58.    
  59.     /******************************
  60.      * GRIFFIN UNIQUE FUNCTIONS
  61.      *******/
  62.    
  63.     /**
  64.      * getMyName() - Returns the animal's name
  65.      *
  66.      * @return The name of the animal as a String
  67.      */
  68.     public String getMyName() {
  69.         return this.name;
  70.     }

  71.     /**
  72.      * getSpeciesName() - Returns the animal's species
  73.      *
  74.      * @return The animal's species as a String
  75.      */
  76.     public String getSpeciesName() {
  77.         return this.species_name;
  78.     }

  79.     /**
  80.      * getLatinName() - Returns the animal's Latin name
  81.      *
  82.      * @return The animal's Latin name as a String
  83.      */
  84.     public String getLatinName() {
  85.         return this.species_latin;
  86.     }

  87.     /**
  88.      * getLocationFound() - Return the location the animal is found
  89.      *
  90.      * @return The location of the animal as a String
  91.      */
  92.     public String getLocationFound() {
  93.         return this.locationFound;
  94.     }

  95.     /**
  96.      * getSleepDuration() - Return how long the animal sleeps
  97.      *
  98.      * @return The length the animal sleeps in hours
  99.      */
  100.     public int getSleepDuration() {
  101.         return this.sleepDuration_hours;
  102.     }

  103.     /**
  104.      * getMovementSpeed() - Returns the max movement speed of the animal
  105.      *
  106.      * @return How fast the animal can move in mph
  107.      */
  108.     public int getMovementSpeed() {
  109.         return this.movementSpeed_mph;
  110.     }

  111.     /**
  112.      * getIsExtinct() - Returns whether the animal is extinct or not
  113.      *
  114.      * @return Returns true or false on whether the animal is extinct
  115.      */
  116.     public boolean getIsExtinct() {
  117.         return this.isExtinct;
  118.     }

  119.     /**
  120.      * calculateSumParity() - Calculates the parity of a 2 number sum
  121.      *
  122.      * @param num1 The first integer to add up
  123.      * @param num2 The second integer to add up
  124.      * @return The NumberParity enumerator holding ODD or EVEN
  125.      */
  126.     public static NumberParity calculateSumParity(int num1, int num2) {
  127.         double sum = num1 + num2;
  128.         double calc = sum;
  129.        
  130.         boolean isEven = true;
  131.         for(int i=0; i < sum; i ++) {
  132.             isEven = !isEven;
  133.         }
  134.         return (isEven) ? NumberParity.EVEN : NumberParity.ODD;
  135.     }

  136. }