Question
Write a class that will model a Dog. We are interested in developing an application that will keep track of every Dog in a certain
Write a class that will model a Dog. We are interested in developing an application that will keep track of every Dog in a certain locality. The properties of a Dog that needs to be captured in a Dog class are: name, weight and years, which could be defined as String, int and int respectively. Every Dog entered into the application will be modeled as a Dog object. These properties should be kept secure from tampering and hence, the class will need to encapsulate these properties.
The client programs of the class will access and change these properties using appropriate getters and setters.
The class should have a method called obtainSize , that will return the size of the dog. Size is a string variable and can take the value of small, medium, large . (Size is not an instance variable). The method obtainSize will determine the size based on the following conditions. If the weight is <= 10, the size is small, else if the weight is between 10 and 30 ( inclusive) the size is medium. For all weights more than 30, size is large. The method obtainSize, returns the value of size. This method takes in no argument from the client programs.
The dog class also needs constructors, both default and full-argument overloaded. Whenever a new dog enters the system, the constructors are used to create new dog objects. Those dogs that are new to the system( for example a new puppy) , but dont have a registered credentials, are created using default constructors, and the properties can be set later on. The class should also provide overloaded constructors that can be used to create new Dog objects.
write the class code for Dog class in Java
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