print out is like Dog-name: d0, age: 0 Dog-name: Lucky, age: 1 Dog-name: GG, age
ID: 3791301 • Letter: P
Question
print out is like
Dog-name: d0, age: 0
Dog-name: Lucky, age: 1
Dog-name: GG, age: 7
Dog-name: d1, age: 12
WolfDog-name: Juno, age: 5, meanness: 9001
WolfDog-name: wd, age: 1, meanness: 10
WolfDog-name: Venti, age: 5, meanness: 100
Dog Notes (also indicated by the arro a. The first three Dog constructors age: int -name: string call the fourth one Initialize with: age name "do" b. The first WolfDog constructor Dog (age:int) name- dl calls the second one. Dog (name:string) age 1 Dog (age:int,name:string) c. The second WolfDog toString0:string returns constructor calls the 2-arg Dog "Dog-name: name, age: age constructor WolfDog meanness:int name "wd WolfDog(meanness:int, ageint) WolfDog (meanness:int, ageint, name: String) toString0 returns: "WolfDog-name: name, age: age meanness: value 1. Write the two classes exactly as shown in the class diagram. 2. Create another DogTester class in package prob3 and copy this code into it: package prob3; public class DogTester public static void main(String[ args) Dog d1. new Dog(); Dog d2 new Dog ("Lucky"); Dog d3 new Dog(7, "GG"); Dog d4 new Dog(12); WolfDog W1 new WolfDog (9001. 5, Juno Wolf Dog W2 new WolfDog (10, 1); WolfDog W3 new WolfDog(100, 5 "Venti"); System.out.println(d1 "Vn d2 "In" d3 "In" d4 "Vn" "In w3); W1Explanation / Answer
package prob3;
public class Dog {
private int age;
private String name;
public Dog() {
// TODO Auto-generated constructor stub
this.age = 0;
this.name = "d0";
}
/**
* @param age
*/
public Dog(int age) {
this.age = age;
this.name = "d1";
}
/**
* @param name
*/
public Dog(String name) {
this.age = 1;
this.name = name;
}
/**
* @param age
* @param name
*/
public Dog(int age, String name) {
this.age = age;
this.name = name;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Dog-name:" + name + ", age:" + age;
}
}
package prob3;
public class WolfDog extends Dog {
private int meanness;
/**
* @param age
*/
public WolfDog(int meanness, int age) {
super(age);
this.meanness = meanness;
// TODO Auto-generated constructor stub
}
public WolfDog(int meanness, int age, String name) {
super(age, name);
this.meanness = meanness;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Wolf" + super.toString() + ", meanness:" + meanness;
}
}
OUTPUT:
Dog-name:d0, age:0
Dog-name:Lucky, age:1
Dog-name:GG, age:7
Dog-name:d1, age:12
WolfDog-name:Juno, age:5, meanness:9001
WolfDog-name:d1, age:1, meanness:10
WolfDog-name:Venti, age:5, meanness:100
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.