Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a public class called Dog to represent the neighborhood canine pet. Include private instance variables for the dog's name, the owner's name, the
Create a public class called Dog to represent the neighborhood canine pet. Include private instance variables for the dog's name, the owner's name, the dog's weight and the dog's age. Provide set and get methods for each class attribute. Create Class Dog: Private Class Instance Members: String dogName, String ownerName, Double weight, Int age Public Class Static Constants (declare to be final): MIN_LEN = 1, MAX_LEN = 20, DEFAULT_STRING= "(undefined)", DEFAULT_WEIGHT=0.0, DEFAULT_AGE = 0, MAX_WEIGHT = 200.0, MAX_AGE = 20 Default Constructor: Dog() -- a default constructor that initializes all members to DEFAULT_STRING, NO_WEIGHT and NO_AGE. Parameterized Constructor: Dog(String dName, String oname, double dwight, int dage) -- a constructor that initializes all members according to the passed parameters. Be sure each parameter satisfies the class requirement for a private class instance member. It does this by calling the mutators that validate parameter data taking possible action if a return value is false. If any passed parameter does not pass the parameter validation test, a default value should be stored in that member. Mutators: Provide public boolean set() methods for the private class instance members. Use the convention as follows: setDogName(...), setOwnerName(...), setWeight(...), setAge(...). Mutators must validate parameter data. When a mutator detects an invalid parameter, the mutator returns false and the existing member data is unchanged. If the parameter is valid, the mutator updates the private class instance member and returns true. Accessors: Provide get() methods for the private class instance members Testing Instructions: Test driver will instantiate a minimum of 3 Dog objects, demonstrate the accessor methods and the mutator methods. You will want to write a helper method to display the object attributes. 1. Instantiate three or more Dog objects, one of them using the default constructor, the other two using the constructor that takes parameters. 2. Immediately display all objects. 3. Mutate one or more members of every object. 4. Display all objects a second time. 5. Perform two explicit mutator tests. For each, call a mutator in an if/else statement which prints one message if the call is successful and a different message if the call fails. 6. Make two access calls to demonstrate that they work. Requirements: 1. Validate all parameter data before setting private instance members. All legal string parameters should be between 1 and 20 characters. All legal weight parameters should be between 0.0 and 200.0. All legal age parameters should be between 0 and 20. Do not use a literal value in your methods. Use a static member to hold values for these limits. 2. mutators should be public boolean methods. Be sure to set the return boolean flag to the client to indicate success (true) or failure (false) in attempting to update private instance methods.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started