Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors: one will be the default constructor, that just sets default values for the name and age; the second constructor will take two parameters, a string to set the name and an integer to set the age. Also, supply methods for setting the name, setting the age, getting the name and getting the age. The class should not contain I/O methods; input of values to the instance variables must be done with a set method or constructor, output of values from the instance variables must be done with get methods. The set method for the name instance variable should ensure that the input is not empty or contain whitespaces (otherwise set a default value). The set method for the age instance variable should validate the input to be between 1 and 4 inclusive(otherwise set a default value). Give Java code for an equals method for the Baby class. Babies count as being the same (i.e. equal) if their names and their ages are exactly identical(names should not be case sensitive). The method will take a Baby type parameter and use the calling object (thus comparing these two objects via name and age); it should return Boolean - true or false as appropriate.
Write Java code for a Baby class. A Baby has a name of type String and an age of type integer.
Supply two constructors: one will be the default constructor, that just sets
default values for the name and age; the second constructor will take two
parameters, a string to set the name and an integer to set the age. Also, supply methods for setting the name, setting the age, getting the name and getting the age.
The class should not contain I/O methods; input of values to the instance
variables must be done with a set method or constructor, output of values from the instance variables must be done with get methods. The set method for the name instance variable should ensure that the input is not empty or contain whitespaces (otherwise set a default value). The set method for the age instance variable should validate the input to be between 1 and 4 inclusive(otherwise set a default value).
Give Java code for an equals method for the Baby class. Babies count as
being the same (i.e. equal) if their names and their ages are exactly identical(names should not be case sensitive). The method will take a Baby type parameter and use the calling object (thus comparing these two objects via name and age); it should return Boolean - true or false as appropriate.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images