Create a public class called Dog to represent the neighborhood canine pet. Include private instance variables...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
The Pangasinan Company has a standard costing system. The following data are available for January: I. Actual variable manufacturing overhead: P25, 500 II. Actual direct labor hours worked: 5, 800...
-
In this assignment, you will create a program that allows theuser to draw in a window using brushes of different sizes andcolors. The user will be able to change the size and color of thebrush using...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Technology guru Tim O'Reilly said this about the publishing industry: " To adapt, publishers need to cannibalize their own business, experimenting with new forms, new formats, and new business...
-
Let K - ATCA, where C > 0. Prove that (a) ker K = coker K = kerA; (b) mg K -- comg K = comg A
-
8.1 How much power do you use? 8.1- How much power do you use? Introduction: Turns out, using electricity is not exactly something that we can get away from in our modern society. In fact, you are...
-
What privacy concerns might arise from the use of biometric authentication techniques? What about the embedding of RFID tags in products such as clothing?
-
Condensed financial data of Fulton Corp. for 2014 and 2013 are presented below. FULTON CORP. INCOME STATEMENT FOR THE YEAR ENDED DECEMBER 31, 2014 Sales ............... $15,200 Cost of goods sold...
-
What are the differences in generic men and women leadership styles, how is it relevant to Canadian context, and how does it positively influence organizational behaviour? Please include all in...
-
Neal Co. allocates overhead cost using a single plantwide overhead rate of \$20 per direct labor hour. Each product unit uses three direct labor hours. Compute the overhead cost per unit.
-
Raspberry eyes (ras) is a sex-linked recessive trait in Drosophila. Eyeless (ey) is an autosomal recessive trait and is epistatic to raspberry eyes (no eyes to score). Black body color (b) is an...
-
There is an overpressure p inside the spherical pressure vessel. The wall thickness t of the vessel can be assumed to be small compared to the radius r of the sphere. The radius is measured at the...
-
What is the role of the Automated Clearing House (ACH) in payment processing? . 10. What is the impact of payment fraud on the finance industry? 11. What is a point-of-sale (POS) system and how does...
-
A torque T = 40 kip - in. is applied at end A of the composite shaft shown. Knowing that the modulus of rigidity is 11.2 106 psi for steel and 4 106 psi for aluminum, determine (1) (4pts) the maximum...
-
the significance of the maturity date in financial instruments, such as bonds or loans? 2. How is the maturity date determined and communicated to investors or borrowers? 3. What factors can...
-
Search for examples of request for proposal documents and develop a template of your own that a company could use to write theirs. What information can you find online about the dean of your...
-
What unique ways are there to distribute soft drinks that you would suggest to soft drink manufacture?
-
Find the work done in pumping all the oil (density S = 50 pounds per cubic foot) over the edge of a cylindrical tank that stands on one of its bases. Assume that the radius of the base is 4 feet, the...
-
Write a fragment of code that will read words from the keyboard until the word done is entered. For each word except done, report whether its first character is equal to its last character. For the...
-
How does a computers main memory differ from its auxiliary memory?
-
Write a program that allows the user to compute the remainder after the division of two integer values. The remainder of x/y is x%y. Catch any exception thrown and allow the user to enter new values.
-
A particle of pure \(\mathrm{NaCl}\) is dissolving in an aqueous liquid solution at \(18^{\circ} \mathrm{C}\). The dissolution of the particle is controlled by mass transfer. The system is vigorously...
-
Calculate the value of Maxwell-Stefan diffusivity for ethanol water at \(40^{\circ} \mathrm{C}\) for ethanol mole fractions of \(0.0,0.2,0.3,0.4,0.7\), and 1.0 . The Fickian diffusivities are...
-
A crystal particle of pure \(\mathrm{NaCl}\) is dissolving in an aqueous liquid (water) solution at \(18^{\circ} \mathrm{C}\). The dissolution of the particle is controlled by mass transfer. The...
Study smarter with the SolutionInn App