Problem:
Design and implement 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 dogs 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.
Solution:
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 ; } 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()); } }
How would you add the breed of the dog?
ReplyDeleteHello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. high anxiety dog crate
ReplyDeleteA very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. high anxiety dog crate
ReplyDeleteAt the point when a dog gets excessively near the border, it gets a stun, however the stun vanishes the minute the dog moves from the limit. local dog groomers
ReplyDeleteHey, can you please help me solve this main class Dog with the following Name,Color, Weight, Height, Habi..........
DeleteHunt, Bark, Play
Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. The dog law is changing
ReplyDeleteSome crates are more useful for training, others for transporting your puppy (or an adult dog) while some can be used for both. puppy cage
ReplyDeleteThe Mystics are an extremely peculiar class! This is presumably the hardest class to use in the game for new individuals as a ton of your abilities are mending. You do get a marvelous transport ability however in the event that you are searching for a class for leveling I would look somewhere else. Best Dissertation Writing Service Online
ReplyDeleteThis is additionally another excellent class for Solo play as you will actually want to assault continually and your harm will go up. Best Assignment Help Online
ReplyDeleteA great content material as well as great layout. Your website deserves all of the positive feedback it’s been getting. I will be back soon for further quality contents. Motorlaarzen
ReplyDeleteBelow you will understand what is important, the idea provides one of the links with an exciting site: WILL CBD CALM DOWN YOUR DOG OR CAT?
ReplyDeleteThis article gives the light in which we can observe the reality. This is very nice one and gives indepth information. Thanks for this nice article. why does my dog lick everything at night
ReplyDelete