Prompt: Design and implement aclass called Dog that contains instance data thatr
ID: 3614429 • Letter: P
Question
Prompt:
Design and implement aclass called Dog that contains instance data thatrepresents the dog's name and age. Define the Dogconstructor to accept and initialize instance data.Include getter and setter methods for the name andage. Include a method to compute and return theage of the dog in "person years" (seven times the dog's age).Include a toString method that returns a one-linedescription of thedog.
Create adriver class called Kennel, whose main methodinstantiates and updates several Dogobjects. In thedriver class use a loop to get user input for thename and age of the dog. continue to loop until the user has nomore dogs to create.
So Far Ihave the Dog class incomplete please help:
public classDog
{
private int Age = 0;
private String Name;
public Dog()
{
Value();
}
public String getName()
{
return Name;
}
public void String setName(String new Name)
{
Name = new Name;
}
public int getAge()
{
return Age;
}
public void int setAge(int new Age)
{
Age = new Age();
}
public void int personYears
{
Value = Age *7
return Value();
}
public String toString()
{
return Age;
return Name;
}
}
_________________________________________________________________________________________
Driver Classincomplete:
import java.util.Scanner;
public class Kennel
{
public static void main (String[] args)
{
String name;
int age;
Scanner scan = new Scanner(System.in);
System.out.println ( "Enter Name ofthe Dog: ");
name = scan.nextLine();
System.out.println ("Enter the age of the Dog: ");
age= scan.nextInt();
}
}
Explanation / Answer
please rate - thanks can't help with the toString-don't follow what it does import java.util.Scanner; public class Kennel { public static void main (String[] args) { String cleanInputBuffer; String name,exitt="exit"; int age; Dog a=new Dog(" ",0); Scanner scan = new Scanner(System.in); while(true) { System.out.println ( "Enter Name ofthe Dog(exit to exit): "); name = scan.nextLine(); if(name.compareTo(exitt)==0) System.exit(0); System.out.println ("Enterthe age of the Dog: "); age= scan.nextInt(); cleanInputBuffer =scan.nextLine(); a.setName(name); a.setAge(age); System.out.println("Dog"+a.getName()+" is "+a.getAge()); System.out.println("Which is"+a.personYears()+" person years "); } } } public class Dog { private int Age = 0; private String Name; public Dog(String name, int age) { Name=name; Age=age; } public String getName() { return Name; } public void setName(String dogname) { Name = dogname; } public int getAge() { return Age; } public void setAge(int dogage) { Age = dogage; } public int personYears() { return Age*7; } public void ttoString() { System.out.println("The dogs name is"+Name); System.out.println("His ageis is "+Age); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.