Question
Class Dog: Attr: Breed - string Color - string feedFactor double name - string mood int (0- dead, 1-dying, 2-sad, 3 normal, 4 content, happy,
Class Dog: Attr: Breed - string Color - string feedFactor double name - string mood int (0- dead, 1-dying, 2-sad, 3 normal, 4 content, happy, 6 excited) age int (months) weight double (lb) Methods: Constr() Constr(string breed, string color, string name) string bark( string command) o mood++ string bark() o change in mood string getFed(double amount) o mood++ o weight+2: if amount > feedFactor*weight //overfed o weight-1: if amount < feedFactor * weight o weight+1 void play(int amtOfTime) //minute unit o mood++ if amtOfTime > 5
*/ public class Dog { //default values final private int DEFAULT_AGE = 1; final private double DEFAULT_WEIGHT = 5; final private double DEFAULT_FEED_FACTOR = 0.3; final private int DEFAULT_MOOD = 3; //normal private String breed, name, color; private double feedFactor, weight; // use in conjunction with weight private int age; //months old private int mood; //(0- dead, 1-dying, 2-sad, 3 normal, 4 content, 5-happy, 6 excited) /** Default constructor to create a Dog object */ public Dog(){ this.breed = "mixed"; this.color = ""; this.name = ""; this.age = DEFAULT_AGE; this.weight = DEFAULT_WEIGHT; this.feedFactor = DEFAULT_FEED_FACTOR; this.mood = DEFAULT_MOOD; } /** * * @param breed - type of dog * @param color - fur color * @param name - given name */ public Dog(String breed, String color, String name){ this.breed = breed; this.color = color; this.name = name; this.age = DEFAULT_AGE; this.weight = DEFAULT_WEIGHT; this.feedFactor = DEFAULT_FEED_FACTOR; this.mood = DEFAULT_MOOD; } /**@see - This method will increase the mood of this instance by 1; * and increase the weight by 2 if over-fed, or by -1 if under-fed; by 1 * @param amount - the feeding amount * @return - the string representing barking sound */ public String getFed(double amount){ this.mood++; if (amount > feedFactor*weight){ //overfeeding this.weight += 2; }else if(amount < feedFactor * weight){//underfeeding this.weight--; }else{ weight++; //normal feeding amount } return this.bark(); } /** * @see - this method will return string represents * the mood of this class instance * @return - a string representing the instance sound with current mood */ public String bark(){ String dogSounds[] = {"", "uhh", "grrr", "waow", "gruff"," gruff gruff", "GRUFFFFF"}; if(this.mood <= 0){ this.mood = 0; } return dogSounds[this.mood]; } /** * @see getter for name * @return the name attribute of this class instance */ public String getName(){ return this.name; } /** * * @param name - new value for the instance attribute "name" */ public void setName(String name){ this.name = name; } ////////====== Your Task ============/////////// /* * 1. complete all the NEEDED getters/setters and methods * 2. create a driver class with a main method to test create an array of Dog objects, * with data obtained from users, and manipulate them */
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