Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Java Design and implement a class called Dog that contains instance data the represents the dog's name and age. Name the Java Class: Dog.

Use Java

Design and implement a class called Dog that contains instance data the represents the dog's name and age.

  • Name the Java Class: Dog. It will contain the information of a dog. (50 points)
  • Name the Driver Class: Kennel. It will test the methods within the Dog Class. (50 points)

1. The Dog Class will include a separate method to perform each of the following:

  • A Constructor. (5 points)
    • The Constructor will initialize the breed, name, and age of the dog when the Dog Class is instantiated.
    • This instance data will be private.
  • A set method to update the dogs breed. (5 points)
  • A set method to update the dogs name. (5 points)
  • A set method to update the dogs age. (5 points)
  • A get method to update the dogs breed. (5 points)
  • A get method to return the dogs name. (5 points)
  • A get method to return the dogs age. (5 points)
  • A method to compute and return the age of the dog in person years. (5 points)
    • A person year is 7 times a dog year.
  • A toString method that returns a one-line description of the dog. (5 points)
    • This will include the breed, name, age, and age in people years.

Below is a list of the instance data Class Dog will need. You MUST keep the breed, name, and age as private. (5 points)

image text in transcribed

2. Create a Driver Class to test Class Dog. Include the following in the Driver Class:

  • (10 points) Instantiate an instance of class Dog within the Driver. Name this object by any dog breed you want. Since the constructor initializes the dog with the breed, a name, and an age when instantiating an Object of class Dog, you will need to initialize the dog with the breed, a name, and an age.
  • (20 points) Create a menu in the Driver that allows you to test each of the methods within the class Dog. Include each of the following selections in your menu: 1. Update the dogs name. 2. Update the dogs age. 3. Update the dog's breed. 4. Display the dog's name only. 5. Display the dog's age only. 6. Display the dog's breed only. 7. Display the dogs age in people years. 8. Display the description of the dog. 9. Exit.
  • (20 points) Make sure all methods work by thoroughly testing the Class Dog with the Class Kennel before submitting.

NOTE: 1. Declare all variables within the data declaration section of each class and method. (-5) 2 Do not get input on the same line as a variable declaration. (-5) 3. Do not place an equation for computation on the same line as declaring a variable. (-5)

PublicPrivate Data T Variable Name Since this rrate Since this is private vou will need a set to Since this is private vou will need a set to Since this is public the data can be directly accessed. Since this is public the data can be directlyy accessed. rivate a set to a get to view it e the name and a get to view it. e the age and a get to view it, ntege Below is a list of each method name, description, the parameter arguments and data type of each parameter argument the method will need, and the retun value and data type of the method. Public Private Return Value and Data Method Name Parameters and Data Types Public No return value or data type. However, the constructor will initialize the dog's name and age. Dog (String breed, String breed: This This is the String name, int age) will contain the dog's constructor. It will breed that is sent to initialize the breed, the constructor when name, and age of each an object of Classbjetdog) Dog is instantiated.instantiated of class String name: ThisDog. will contain the dog's name that is sant to the constructor when an object of Class Dog is instantiated. int age: This will contain the dog's age that is sent to the constructor when an object of Class Dog is String newBre This will initialize the breed. dog's breed if the user wants to chanee it tring data type. will retum 3 15er to v1ew of the dog as a string. the dog's current breed through the the breed of the dog. Void. No return value or setNameString data type. String newName: Updates the dog's This will iniializethe name. dog's name if the user wants to chanee it. String. Returns the name of getName) the dog as a string. None. This will retum |Allows user to vie the dog's current the name of the dog. Void. No return value of tAg(intAge) data type. integer newAge This will initialize the dog's age should the user want to change Updates the dog's age. Integer. Retums the age of getAgeO the dog as an integer. None. This will returm the dogs Allows user to view the age of the dog. the method name. Integer. Retuns the age of person the dog in "people years" as an ntege Years) None. This will returm the dogs age in the dog in people people years through years. the method name. Computes the age of String. Returns a one-line toString0 description of the dog as a None. This will retum a description of description of the dog the dog through the using the dog's breed, method name. Creates a one-line name, age, and age in people years

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions