ArrayList of Cats

Create a Cat class. The cat is a noble creature that has the following attributes:

  • name
  • breed
  • color
  • number of legs
  • litter type //scoopable, crystals, regular, none //do you want to try an enum here? //These are the only valid values.

We need multiple constructors for Cat

  • A zero parameter constructor
  • A constructor where number of legs defaults to 4 and litter type defaults to regular
  • A constructor where the number of legs is defaulted to 4. The rest are passed as explicit parameters
  • A constructor that has all of the attributes as explicit parameters
  • Any more?

The Cat also has methods associated with the class.

  • Getters and Setters for ALL attributes
  • A method that counts all of the cat’s legs in an ArrayList of cats
  • A method that totals all of the cat’s weights in an ArrayList of cats
  • A toString method that presents a cat’s information in a pretty and readable manner

Do a good job on this Cat class as we might see this later and improve upon it.

Create a CatTester class. Create at least 10 cats and place them in an ArrayList in the CatTester class. Make sure at least two of your cats have a name that starts with an “f”.

  • Create 4 additional cats by generating a random number of legs for each of these cats. Generate a random number between 1 and 6, and this will be the number of legs the cat has. We will have no cats with 0 legs, or more legs than 6. See the class Random to help. This should be in a loop.
  • Make sure you thoroughly test all of your constructors in your CatTester class. SOP all your cats to the console. Make sure there is helpful output which includes the text “All of the cats are:” and that when you output your cats that the output is readable and “pretty”.
  • Remove all cats that have less than 4 legs. SOP all remaining cats to the console, including meaningful text that states “All cats with 4 or more legs after removing cats with less than 4 legs:”.
  • SOP all of the cat’s names that start with an upper or lower case “f”, with meaningful text. Then remove these cats from your ArrayList. SOP all remaining cats to the console, with meaningful text.
  • SOP the cat with the index of 4. SOP the cat, identifying this cat with meaningful text such as “Cat number 5 is:”. (Remember the index starts at 0, so the cat at index 4 will be the fifth cat).
  • Change the weight of the cat at index 6. Make sure the cat exists before you do this. SOP meaningful text that identifies the cat and its weight before and after the change.
  • Replace the cat at index 2. Make sure the cat exists before you do this. The cat that replaces the previous cat will have a name of “Snoot”, a breed of “calico”, a color of “orange”, 4 legs, a weight of 7, and a litter type of scoopable. SOP, with meaningful text, the entire ArrayList of cats.
  • Using the ArrayList produced in step g., total the weight of all of the cats left in the list, using your method from Cat. SOP this information.
  • Using the ArrayList produced in step g., total the number of legs of all of the cats left in the list, using your method from Cat. SOP this information.
  • Verify that all of your output from the previous steps is correct and meaningful. Test, test, test!

Turn in all of the .java necessary to build, run and test your class

Comparable

  • Implement the Comparable interface from the Java API in your Cat class. Your cats should be compared and sorted by their weight, lowest to highest.
  • Write Homework8Tester.java that creates at least 10 cats and places them in an ArrayList. (You can copy and paste from your previous CatTester if you would like.)
  • Sort your cats in Homework8Tester.java and verify that your implementation of Comparable is correct. SOP meaningful information to the console that shows the cats before and after they are sorted. No messiness in the output!

Doubler

  • Write an Interface named Doubler. It contains one method signature (declaration) that must meet the following specification:
Object getDouble(Object anyObject);
  • Implement the Doubler interface for a Rectangle. (Utilize the Rectangle in the Standard Java API.) Name it RectangleDoubler.java. The getDouble method should double the width and height of the rectangle, but leave the same x and y positions of the top left corner, and return this new “doubled” rectangle. Turn in the Doubler.java, RectangleDoubler.java and DoublerTester.java files (which doubles at least 5 rectangles).
  • Now implement the Doubler interface for your Cat class. Leave the Comparable implementation, and it should still work!. For Cat, the Doubler interface is used to double the weight of your Cat.
  • Add to your DoublerTester. Test the implementation of the Doubler Interface for your Cat class and your RectangleDoubler class. Make sure you print sufficient, readable, meaningful output to the console that shows your interface and implementation are successful.
Academic Honesty!
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.