Page 1 of 1

Java Programming Create a class Holding, which represents an investment, and has Add methods: Add also a method update()

Posted: Fri Apr 29, 2022 7:08 am
by answerhappygod
Java Programming
Create a class Holding, which represents an investment, and
has
Add methods:
Add also a method update() which first calls findDividend.
If reinvest is false, it should return the dividend amount found --
paying that out as cash immediately. If reinvest is true,
instead use that money to buy (you have a method for this) more of
the holding, and then return 0.
-------
A Holding's shareprice may rise or fall, meaning that our
shares are worth more or less. Create an interface
PriceChange which requires a method variation(double price) that
returns a double. This method will take a current shareprice
and return an amount to change the price by (not the changed
price).
Create a class Noisy that implements PriceChange. In its
variation method, no matter the price, return a random amount
between 75 and -50 cents (inclusive).
Create a class MarketRandom that implements PriceChange.
It should have an instance variable volatility, which is a
percentage and cannot be more than 100%. In its variation
method, return a random amount from volatility% to -volatility% of
the current price. So if volatility is 10%, and the price
started as 30, the result would be a random number between -$3 and
$3.
Add to Holding an instance variable of type PriceChange,
priceChanger, which defaults to a MarketRandom with 5%
volatility
Also in Holding, in the update method use priceChanger to update
the price of the holding (Do not allow the share price to go below
0) Dividends are determined using the old price of the
holding, but if reinvesting, the new shares are bought at the
new price. Think about what order to do things
in.
----
Now we will take out taxes and administrative fees when shares
are bought and sold.
Create an interface FeeScheme that requires methods
feeAtBuy(amount) and feeAtSell(amount) each of which takes a double
representing an amount and returns a double representing the
amount of fees to be taken out (not the amount left
over!).
Create a class ShortTermFee that implements FeeScheme. A
1% fee is taken on each buy. On sell taxes are 25%.
Create a class LongTermFee that implements FeeScheme. On
buy take a fee of 1% if it is over 1000, otherwise 0. On
sell, 0 on amounts up to 1000, 10% of the money over 1000 but under
10,000, and 15% of money over 10,000. So if they were selling
15,000, that would be 1000 at 0% + 9,000 at 10%. + 5000 at 15% = 0
+ 900 + 750
Create a class Exempt that implements FeeScheme. It just
has an administrative fee (never negative, default to $1) and a
certain number of free transactions (default to 10). After
all the free transactions (buy or sell) are used up, take the
administrative fee on every transaction, or the full amount of the
transaction, if this is less than the fee.
Add to Holding a variable fee of type FeeScheme. By
default, Holdings have ShortTermFee schemes.
In buy, first use feeAtBuy and subtract the appropriate
fees from the amount being bought before actually buying
shares.
When selling, subtract the full amount to sell from the shares,
but then take out feeAtSell before returning the amount.
So, if I try to buy $100 of a holding
with a ShortTermFee scheme, I will end up owning $99 worth, because
1% was used up on fees.
If I own $500 of a Holding with an Exempt scheme that is out of
free transactions and I try to sell $100, I will end up still
owning $400 worth, but only $99 will be paid out because $1 was
used on fees.
In the update method, if not reinvesting dividends, use
feeAtSell to determine fees to subtract from the dividend value
before returning.