Good Dog This unit%u2019s readings introduce the concept of constructors , metho
ID: 3540036 • Letter: G
Question
This unit%u2019s readings introduce the concept of constructors, methods that share the same name as a class that are run whenever objects of that class are instantiated. Constructors allow you to define and build the World in a specific way. Each time you press the Reset button in the Greenfoot workspace, you force the World to redraw itself to its initial state, invoking the constructor methods of the actors.
In this Application, you place Actor subclasses called Dog into an empty subclass of World called DogWorld. You build a world of dogs and govern their behavior according to specific methods, some already defined and some that you define yourself. Download, unzip, and open the good-dog.zip scenario and complete each of the following exercises.
public class Dog {
private int age;
private String owner;
private Dog mother;
private Dog father;
public Dog() {
super();
}
public int getAge()
{
return this.age;
}
public void setAge(int age)
{
this.age=age;
}
public String getOwner() {
return owner;
}
public void setOwner(StringnewOwner) {
this.owner =newOwner;
}
public Dog getMother() {
return mother;
}
public void setMother(Dog m) {
this.mother = m;
}
public Dog getFather() {
return father;
}
public void setFather(Dog father) {
this.father = father;
}
public void birthday ()
{
//calculate and return the birthday of the dog from its age.
//But in normal case age is calulated from birthday not the reverse..
//so i think there is a problem here with this uml
//Any ways this is the representation of UML : BirthDay : void
}
public boolean hasMother ()
{
if(this.getMother()!=null)
{
//return boolean value true/false
return true;
}
else
{
return false;
}
}
public boolean hasFather()
{
if(this.getFather()!=null)
{
//return boolean value true/false
return true;
}
else
{
return false;
}
}
}
Explanation / Answer
Do you need solution to this?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.