For this assignment, you will write a class for animals at a shelter. Your file should be called AnimalLASTNAME.java where LASTNAME is replaced with your last name (not in all capital letters). Be sure to name your class and constructor according to this file name.
The class will contain the following six attributes:
animal
name
age
weight
specialNotes
ID_NUMBER
The animal attribute should state wether the animal admitted is a "dog", "cat", "rabbit", or "other". These should be the only possible values. (How might you restrict this?) This will not change.
The name attribute should be a string passed in the parameter. This will not change during the animal's stay at the shelter.
The age should be in years.
The weight should be in pounds and expressed in half-pounds.
Special notes should be an optional field. If nothing is provided, this attribute should be equal to "Nothing written." You will write the following methods as well. Be sure your methods follow the description.
A constructor that takes in information on the name and the animal type.
A getter for all the attributes. A setter for the attributes where it makes sense.
A toString() method that returns a full description of the shelter animal within a string as a complete sentence.
A main method where You create 5 animals. Make sure to set all their attributes. Print the results using the toString method. In at least one of your methods, you need to include a conditional statement whose boolean expression involves an int. Conditional statements are if statements. Here is an example of an if statement written for Java: if ( num == 4){ s = "It's a four"; } The above if statement checks if the int num is equal to 4. If it is, the variable s is set to "It's a four". Here is an example where more than one number is considered: if ( num == 4){ s = "It's a four"; }else if (num == 5){ s = "It's a five"; }else{ s = "It's not four or five."; }
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.