Cow.java

  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package edu.nwmissouri.animalList;

  7. /**
  8.  * Cow class (derived subclass of the superclass Animal)
  9.  *
  10.  * @author Harika_Chintala
  11.  */
  12. public class Cow extends Animal {

  13.     /**
  14.      * Cow Constructor
  15.      *
  16.      * @param name - the name of this cow
  17.      */
  18.     public Cow(String name) {
  19.         super(name);
  20.     }
  21.     //@Override

  22.     public void eat() {
  23.         System.out.println("I eat like Yumm yumm yumm!!");
  24.     }

  25.     @Override
  26.     public void speak() {
  27.         System.out.println("I am a Cow.. " + this.name);
  28.     }

  29.     //@Override
  30.     public void child() {
  31.         System.out.println("I can give birth to one child at once");
  32.     }
  33.     //@Override

  34.     public void color() {
  35.         System.out.println("I can be in black, brown and white color ");
  36.     }

  37.     @Override
  38.     public void move() {
  39.         System.out.println("When I move, I move, move, move...");
  40.     }

  41.     /**
  42.      *
  43.      * @param morningMilkProdection is of type double
  44.      * @param eveningMilkProduction is of type double
  45.      * @return double value
  46.      */
  47.     public double getCowAddition(double morningMilkProdection, double eveningMilkProduction) {
  48.         return morningMilkProdection + eveningMilkProduction;
  49.     }

  50.     /**
  51.      *
  52.      */
  53.     public void studentCow() {
  54.         double morningMilkProdection = 2.3;
  55.         double eveningMilkProduction = 1.5;
  56.         double perDayMilkProduction = getCowAddition(morningMilkProdection, eveningMilkProduction);
  57.         System.out.println("I am " + this.name + ", I produce " + morningMilkProdection + "liters Of milk in the morning and " + eveningMilkProduction + "liters in the Evening, Overall I will produce " + perDayMilkProduction + "\"liters per\" day");
  58.     }

  59.     public enum EnumDirections {
  60.         EAST, WEST, SOUTH, NORTH;
  61.     }

  62.     public void directionToGo(EnumDirections d) {
  63.         if (null == d) {
  64.             System.out.println("\"I am travelling towards EAST\"");
  65.         } else {
  66.             switch (d) {
  67.                 case EAST ->
  68.                     System.out.println("\"I am travelling towards EAST\"");
  69.                 case WEST ->
  70.                     System.out.println("\"I am travelling towards WEST\"");
  71.                 case SOUTH ->
  72.                     System.out.println("\"I am travelling towards SOUTH\"");
  73.                 default ->
  74.                     System.out.println("\"I am travelling towards NORTH  \"");
  75.             }
  76.         }
  77.     }

  78.  
  79. }