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

Create a java program as specified below and exhibit the working of your class w

ID: 3684921 • Letter: C

Question

Create a java program as specified below and exhibit the working of your class with some inputs in a driver class.

Class: Pet (File name: Pet.java)

private data members:

Pet name (a String)

Owner name (a String)

color (a String)

protected data member:

sex (a string, will only hold one of the four values: MALE, FEMALE, SPAYED and NEUTERED.)

Public Methods:

Pet (String name, String ownerName, String color); //Constructor

String getPetName();

String getOwnerName();

String getColor();

void setSex(int sexid);

String getSex(); // Should return the string equivalent of the gender, e.g the string “male” etc.

String toString(); // Should return the name, owner’s name, age, color, and gender (use getSex()), A Sample (preferred) return value by toString is as follows:

Spot owned by Mary

Color: Black and White

Sex: Male

Interface: Boardable (File name: Boardable.java)

This interface, should include the following public methods:

void setBoardStart(int month, int day, int year);

void setBoardEnd(int month, int day, int year);

boolean boarding(int month, int day, int year);

Class: Cat (File name: Cat.java)

This class should extend the Pet class and implement the Boardable interface. In addition to the data members and methods inherited from Pet, the Cat class should have a private data member hairLength( a string).

public methods:

Cat (String name, String ownerName, String color, String hairLength);

// Do not forget to call super.

String getHairLength(); // returns the string hairLength

String toString()

/* method that returns a String that identifies the pet as Cat and returns a complete description of the cat, including the values stored in the Pet parent class.*/

A Sample (preferred) return value by toString is as follows:

CAT:

Tom owned by Bob

Color: black

Sex: spayed

Hair: short

In order to implement the Boardable interface define new data members to store the boarding start and end dates, implement the setBoardStart and setBoardEnd methods to store values for these data members. Also implement the boarding method to return true if the given data is between the start and end dates, otherwise it returns false. Note: You should also return true if the given date is equal to the start or end date.

Class: Bird (File name: Bird.java)

This class should extend the Pet class. In addition to the data members and methods inherited from Pet , the Bird class should have a private boolean data member called feathersClipped.

Following are the public methods that this class should provide:

Bird(String name, String ownerName, String color) ;

/* Constructor should initialize the feathersClipped data member to false. Do not forget to call super. */

boolean clipped(); // returns the value of feathersClipped

void setClipped(); // sets the the value of featherClipped to true

String toString()

/* method that returns a String that identifies the pet as Bird and returns a complete description of the bird, including the values stored in the Pet parent class. */

A Sample (preferred) return value by toString is as follows:

BIRD:

Poly owned by Steve

Explanation / Answer

Pet.java

package com.chegg.test;

enum Sex {
   male, female, spayed, neutured
}

/**
* Class to show pet characteristics
*
* @author yourName
*
*/
public class Pet {

   // private data members:
   private String petName;
   private String ownerName;
   private String color;
   // protected data member:
   protected String sex;

   Pet(String name, String ownerName, String color) {
       this.petName = name;
       this.ownerName = ownerName;
       this.color = color;
   }

   /**
   * @return the sex
   */
   public String getSex() {
       return sex;
   }

   /**
   * @param sex
   * the sex to set
   */
   public void setSex(String sex) {
       this.sex = sex;
   }

   /**
   * @return the petName
   */
   public String getPetName() {
       return petName;
   }

   /**
   * @return the ownerName
   */
   public String getOwnerName() {
       return ownerName;
   }

   /**
   * @return the color
   */
   public String getColor() {
       return color;
   }

   public String toString() {
       return "A " + getPetName() + " owned by " + getOwnerName() + " Color:"
               + getColor() + " Sex: " + getSex();
   }
}

Boardable.java

package com.chegg.test;

/**
* Interface to implement logic
*
* @author yourName
*
*/
public interface Boardable {

   void setBoardStart(int month, int day, int year);

   void setBoardEnd(int month, int day, int year);

   boolean boarding(int month, int day, int year);
}

Cat.java

package com.chegg.test;

import java.util.Calendar;
import java.util.Date;

/**
* Class to show Cat Characteristics
*
* @author yourName
*
*/
public class Cat extends Pet implements Boardable {

   // private data member
   private String hairLength;

   public int startMonth;
   public int startDay;
   public int startYear;
   public int endMonth;
   public int endDay;
   public int endYear;

   public Cat(String name, String ownerName, String color, String hairLength) {
       super(name, ownerName, color);
       this.hairLength = hairLength;
   }

   /**
   * @return the hairLength
   */
   public String getHairLength() {
       return hairLength;
   }

   public String toString() {
       return "CAT:" + " " + getPetName() + " owned by " + getOwnerName()
               + " Color: " + getColor() + " Sex: " + getSex() + " Hair: "
               + getHairLength();
   }

   public void setBoardStart(int month, int day, int year) {
       this.startMonth = month;
       this.startDay = day;
       this.startYear = year;
   }

   public void setBoardEnd(int month, int day, int year) {
       this.endMonth = month;
       this.endDay = day;
       this.endYear = year;
   }

   public boolean boarding(int month, int day, int year) {

       Calendar c = Calendar.getInstance();
       c.set(year, month, day, 0, 0);
       c.set(Calendar.HOUR_OF_DAY, 0);
       c.set(Calendar.MINUTE, 0);
       c.set(Calendar.SECOND, 0);
       c.set(Calendar.MILLISECOND, 0);
       Date testDate = c.getTime();

       Calendar c1 = Calendar.getInstance();
       c1.set(startYear, startMonth, startDay, 0, 0);
       c1.set(Calendar.HOUR_OF_DAY, 0);
       c1.set(Calendar.MINUTE, 0);
       c1.set(Calendar.SECOND, 0);
       c1.set(Calendar.MILLISECOND, 0);
       Date startDate = c1.getTime();

       Calendar c2 = Calendar.getInstance();
       c2.set(endYear, endMonth, endDay, 0, 0);
       c2.set(Calendar.HOUR_OF_DAY, 0);
       c2.set(Calendar.MINUTE, 0);
       c2.set(Calendar.SECOND, 0);
       c2.set(Calendar.MILLISECOND, 0);
       Date endDate = c2.getTime();
       return ((testDate.after(startDate) && testDate.before(endDate))
               || testDate.equals(startDate) || testDate.equals(endDate));

   }

}

Bird.java

package com.chegg.test;

/**
* Bird Class to show the Characteristics of a bird
*
* @author yourName
*
*/
public class Bird extends Pet {

   private boolean feathersClipped;

   Bird(String name, String ownerName, String color) {
       super(name, ownerName, color);
       this.feathersClipped = false;
   }

   /**
   * @return the feathersClipped
   */
   public boolean isFeathersClipped() {
       return feathersClipped;
   }

   /**
   * @param feathersClipped
   * the feathersClipped to set
   */
   public void setFeathersClipped(boolean feathersClipped) {
       this.feathersClipped = feathersClipped;
   }

   public String tostring() {
       return "BIRD: " + getPetName() + " owned by " + getOwnerName();
   }
}

DriverTest.java

package com.chegg.test;

/**
* Class to test the Inheritance concept
*
* @author yourName
*
*/
public class DriverTest {
   public static void main(String[] args) {
       // Instantiating Pet Class
       Pet pet = new Pet("Spot", "Mary", "Black and White");
       // Setting only allowed for sex
       pet.setSex(Sex.male.toString());
       System.out.println(pet.toString() + " ");
       // Instantiating Cat Class
       Cat cat = new Cat("Tom", "Bob", "black", "short");
       // Setting only allowed for sex
       cat.setSex(Sex.spayed.toString());
       // Setting board Start Date
       cat.setBoardStart(3, 4, 2016);
       // Setting board End Date
       cat.setBoardEnd(3, 6, 2016);
       //Finding Boarding Info
       System.out.println("Boarding Info: "+cat.boarding(3, 6, 2016));
       System.out.println(cat.toString() + " ");
       // Instantiating Bird Class
       Bird bird = new Bird("Ploy", "Steve", null);
       System.out.println(bird.tostring());
   }
}

Output:

A Spot owned by Mary
Color:Black and White
Sex: male

Boarding Info: true
CAT:
Tom owned by Bob
Color: black
Sex: spayed
Hair: short

BIRD:
Ploy owned by Steve

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote