Question
In Java 8.0 The Stock class. The Stock class represents a stock. The Stock class will have a ticker symbol, a current price, a dividend
In Java 8.0
The Stock class. The Stock class represents a stock. The Stock class will have a ticker symbol, a current price, a dividend rate, the date the dividend is paid, the number of shares owned, the cost basis of the stock, and the capital gains earned by the stock. The class should have the following methods:
-
getTickerSymbol: takes no input and returns a String that is the stock market ticker symbol. The ticker symbol will never change.
-
getCurrentPrice: takes no input and returns a double that is the current price for a share of the stock.
-
setCurrentPrice: takes a double as input and returns nothing. Changes the current price of a share of the stock.
-
getDividendRate: takes no input and returns a double that is the dividend rate for the stock.
-
setDividendRate: takes a double as input and returns nothing. Changes the dividend rate for the stock.
-
getDividendDate: takes no input and returns a Date that is the dividend date for the stock, or the method returns null if the stock does not pay dividends.
-
setDividendDate: takes a Date as input and returns nothing. Changes the dividend date for the stock. If the stock does not pay dividends, the dividend date should be null.
-
getNumberShares: takes no input and returns an int that is the number of shares owned in the stock.
-
getCostBasis: takes no input and returns a double that is the cost basis for the owned shares.
-
getCapitalGains: takes no input and returns a double that is the total capital gains earned so far.
-
payDividend: takes no input and returns a double. Returns the dividend rate multiplied by the number of shares.
-
buy: takes an int and a double as input and returns a double. The input values are the number of shares being purchased and the commission. Increases the number of shares owned in the stock by the number of shares purchased. Increases the cost basis for the stock by (number of shares purchased x the current price) + commission. Returns the (number of shares purchased x the current price) + commission.
-
sell: takes an int and a double as input and returns a double. The inputs are the number of shares being sold and the commission. If number of shares being sold is greater than the number currently owned, returns 0 and makes no other changes. Otherwise, the number of shares owned is decreased by number of shares sold. The cost basis is decreased by the ratio of number of shares sold to the number of shares originally owned. (For example, if you sell 1/3 of your shares, the cost basis should decrease by 1/3.) The capital gains is increased by the difference between (number of shares sold x the current price) - commission and the amount that the cost basis decreased. Returns (number of shares sold x the current price) - commission.
-
split: takes two int values as input and returns a double. The input values are the numerator and the denominator of the split fraction. If either input value is zero, nothing is done and 0 is returned. Otherwise, the number of owned shares changes by the ratio numerator / denominator. (For example, split(2,1) should double the number of shares while split(1,2) should result in one half the number of shares.) If the resulting number of shares contains a fractional share (not a whole number), then the fractional share must be sold so that the final number of shares is a whole number. This is exactly like selling shares normally, except that no commission is charged. The amount returned is the amount of money made from the sale (amount sold times price), and if there is no fractional share because the result of the split is a whole number, then 0 should be returned.
The Stock class should have two constructors:
-
One has two inputs: a String (the ticker symbol) and a double (the current price).
-
One has four inputs: a String (the ticker symbol), a double (the current price), a Date (the dividend date), and a double (the dividend rate).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started