ABSTRACT PART A · Create an abstract class Creature with an instance variable strength and abstract methods: eat(), which will represent the animal eating, call(), which will represent the sound the...



ABSTRACT


PART A


· Create an abstract class Creature with an instance variable strength and abstract methods: eat(), which will represent the animal eating, call(), which will represent the sound the animal makes, and move() which will represent how it moves. (When you fill in these methods later, you will mostly just print out messages saying what they do foreach specific class.)


· In your main, create an array of 10 Creatures (you will fill it with your actual creature types later). Write code that would have each one in the array eat, move, and do their calls. Notice you can write this code without having created any non-abstract classes and their methods, but you can't run yet.


· Inheriting from Creature, create abstract classes to represent carnivores, which only eat meat, and herbivores, which only eat vegetables (just have the eat method print what the creature is eating).


· Then create four non-abstract classes for specific types of creature, two of which are carnivores, and two herbivores (you may create any type of creature that amuses you).


· For these final four creature classes, don't override eat (already filled in for eating meat or vegetables) but fill inmove and call in ways appropriate to the creature. Give one of the classes an appropriate extra instance variable which is used in some way in move or call, and for at least one other creature use strength in some way in move or call.


· Then go back into main and fill up your array with various creatures andsee that the code you wrote successfully calls all the different versions of the eat, call, and move methods.




PART B


· Create an abstract class Holding, which represents an investment, and has:


· a double shares, representing how many shares are owned (It is possible to own fractional shares.)


· a double shareprice, representing the current price of each share


· a boolean reinvest, which determines whether profits are used to buy more shares, or simply paid out


· These numbers should never go below 0.


· It should have a method getValue() which returns shares * shareprice.


· It should have a method buy (double amt) which increases the number of shares by amt / shareprice and does not return.


· It should have a method sell(double amt) which decreases the number of shares by amt / shareprice, and returns the same amount it was given (assuming the holding had that much).


· In these methods, decide on appropriate ways to handle negative arguments and attempts to sell more than the current value of the Holding.


· It should have an abstract method update (int month) which returns a double.

Apr 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here