Question: Help me understand and walk through this task. Please attempt only if you can do every part and explain and don't miss out certain tasks.
Help me understand and walk through this task. Please attempt only if you can do every part and explain and don't miss out certain tasks. I've already done this code myself but i need reassurance hence the post and want to compare how efficiently I could have done it.
//java
Requirements:
The base class, from which all your more specific types of pet will derive, is going to be named Pet. Create the class such that pets have a name, an age and a cost property. You will also need to create a getter and setter method for each property. Youll need one additional method in the Pet class, named makeNoise(). This method does not need to accept any parameters, and doesnt need to return anything. Calling a Pets makeNoise() method should cause a message to be printed to the console: NAME doesnt make any noise, where NAME is replaced with the Pets name. I would also recommend declaring this class abstract, which means that no instances of the Pet class can be constructed. The only way to create a Pet is to instantiate an object that extends the class.
For now, were going to create three classes that extend Pet: a Cat class, a Dog class and a Goldfish class. You will need to override the makeNoise() method in the Cat and Dog classes such that the correct animal noise is written to the console. Goldfish should use the super keyword in their makeNoise() method to invoke the overridden method in the Pet class, as well as printing Theyre a goldfish! to the console. At this stage, you should create a class named Controller or Main, with a main() method that instantiates a Cat, a Dog and a Goldfish and checks their makeNoise() methods are working properly.
Were going to create an interface that is used to represent Pets that can be stroked. A pet that can be stroked will have a stroke() method, accepting no parameters and returning nothing. Create a Strokeable interface that requires classes implementing it to have such a method. Modify your Cat and Dog classes so that they implement the Strokeable interface. When stroked, Dogs should write NAME enjoys being stroked. to the console, and the makeNoise() method should be called. Cats, on the other hand, should write NAME wanders off and ignores you. without making a noise. Goldfish should not be stroked. Modify your main method to include some tests for the new stroke() method for both Cats and Dogs, to demonstrate that your newly-added code is working well.
Add a new class to your eclipse project named PetShop, and write a default (no parameter) constructor for it that creates an array of 10 Pets to represent the shops stock. You can choose how many Cats, Dogs and Goldfish the shop will have in stock to suit yourself: it doesnt really matter. One a Pet has been sold, its entry in the array will be replaced with a null. Your Pet shop will need a number of methods to allow customers to actually buy pets. The buyCat(), buyDog() and buyGoldfish() methods should search through the PetShops array of stock for the first suitable animal, replace its entry in the stock array with null, and return the pet to the customer. If the store is out of the requested type of animal, it should return null. The PetShop class will also have a buyPetByCost() method, that accepts a double as a parameter representing the cash a customer can afford to spend. This method will return the most expensive animal from its stock that the customer can afford. If the customer cannot afford any of the animals in stock, the method can return null. Add code to your main() method to create a pet shop, and demonstrate that each of the buying methods is working properly. Remember to check to see if they returned null.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
