In: Computer Science
BEFORE YOU START MAKE SURE TO SEND AS A TEXT FILE NOT PDF OR PICTURES. WRITE IN A NEXT FILE IN JAVA ECLIPSE FORMAT. WILL BE POSTING THE CODE ON JAVA ECLIPSE. ALSO WILL GIVE THUMBS UP
Write a class called Dog that contains instance data that represents the dog’s name and age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in “person years” (seven times the dog’s age). Include a toString method that returns a one-line description of the dog. Create a driver class called Kennel, whose main method instantiates and updates several Dog objects.
/* Dog.java */
public class Dog
{
private int age;
private String name;
public Dog(int age,String name)
{
this.age = age;
this.name = name;
}
public String setDogName(String name)
{
this.name = name;
return name;
}
public int getDogName()
{
return age;
}
public int setDogAge(int age)
{
this.age = age;
return age;
}
public int getDogAge()
{
return age;
}
public int computeDogAge()
{
this.age = age*7;
return age;
}
public String toString()
{
String dogsname= "Dog's name: ";
String dogsage= "Dog's age: ";
return dogsname + name + "\t" +
dogsage + age ;
}
}
/* Kennel.java */
public class Kennel {
public static void main (String[] args)
{
Dog dog1 = new Dog(1,"Lucky");
Dog dog2 = new Dog(2,"Starc");
Dog dog3 = new Dog(5,"Lutchy");
dog1.setDogAge(9);
System.out.println(dog1);
dog2.setDogName("Azzam");
System.out.println(dog2);
System.out.println(dog3);
System.out.println();
System.out.println("Dog's ages in person years: ");
System.out.println(dog1.computeDogAge());
System.out.println(dog2.computeDogAge());
System.out.println(dog3.computeDogAge());
}
}
/* OUTPUT */