Question: In Java, design and implement a class called Cat. Each Cat class will contain three private variables - an integer representing its speed, a double
In Java, design and implement a class called Cat. Each Cat class will contain three private variables - an integer representing its speed, a double representing its meowing loudness, and a String representing its name. Using the Random class, the constructor should set the speed to a random integer from 0 to 9, the meowing loudness to a random double, and the name to anything you want; the constructor should take no parameters. Write get and set methods for each variable, and one that prints all the variables. Finally, write a main method to test the methods in the class. The three variables must be private.
Then design and implement a class called CatOwner. Each CatOwner will have three private variables: a String representing the owner name, an integer representing how much cat food is left, and a cat; each cat should be an instance of the Cat class. The constructor can name the CatOwner anything you want, and the supply of food should be a random number greater than or equal to 10 and less than 50. Each cats name should be set to Tinkles. The constructor for CatOwner should take no parameters. Write get and set methods for the owners name, the food supply, and all the properties of the cat; also write a feedCat method that decreases the food supply by 1 and prints that the cat was fed. Next, write a method to print all class variables. Finally, write a main method to test your methods.
Design a driver class which instantiates two CatOwner objects. Next, perform the following five steps:
1. Change the name of the first cat owner to John Doe and his dogs name to Whiskers. Change the name of the second cat owner to George Washington. 2. Increase the meowing loudness of the first cat owners cat by .1, and set the speed of the second cat owners cat to 5. 3. Double the food supply of the first cat owner, and set the food supply of the second to 25. 4. Have the first cat owner feed his cat three times, and have the second cat owner feed his cat twice. 5. Print out all the information for both cat owners.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
