1. The Stock class. The Stock class represents a stock account. The class should have the following...
Fantastic news! We've Found the answer you've been seeking!
Question:
1. The Stock class. The Stock class represents a stock account. The class should have the following methods:
- String getCompanyName(): returns the company name for the stock.
- void setCompanyName(String name): changes the company name for the stock.
- String getTickerSymbol(): returns the stock market ticker symbol.
- void setTickerSymbol(String tickerSymbol): changes the stock market ticker symbol.
- double getCurrentPrice(): returns the current price for a share of the stock.
- void setCurrentPrice(double price): changes the current price of a share of the stock.
- int getNumberShares(): returns the number of shares owned in the stock.
- double getCostBasis(): returns the cost basis for the owned shares.
- double getCapitalGains(): returns the total capital gains earned so far.
- double buy(int numShares, double commission): increases the number of shares owned in the stock by numShares. Increases the cost basis for the owned shares by (numShares x the current price) + commission. Returns the (numShares x the current price) + commission.
- double sell(int numShares, double commission): if numShares is greater than the number currently owned, returns 0 and makes no other changes. Otherwise, the number of shares owned is decreased by numShares. The cost basis is decreased by the ratio of numShares 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 (numShares x the current price) - commission and the amount that the cost basis decreased. Returns (numShares x the current price) - commission.
- double split(int ratioNumerator, int ratioDemonimator): if either input value is zero or negative, nothing is done and 0 is returned. Otherwise, the number of owned shares changes by the ratio ratioNumerator / ratioDenominator. (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. Follow the same logic as for the sell method except that no commission is charged, and the value returned should be the same as what would be returned by the sell method if the commission were 0. If there is no fractional share (the initial result of the split is a whole number), then 0 should be returned.
The Stock class should have two constructors:
- One has input String tickerSymbol, double currentPrice and sets the ticker symbol and the current price associated with the Stock.
- One has input String companyName, String tickerSymbol, double currentPrice and sets the company name, ticker symbol, and the current price associated with the Stock.
- The Cash class. The Cash class represents an account holding money reserves. The class should have the following methods.
- double getBalance(): returns the current balance in the account.
- double getSavingsRate(): returns the interest rate applied to positive balances.
- void setSavingsRate(double savingsRate): changes the interest rate applied to positive balances.
- double getLoanRate(): returns the interest rate applied to negative balances.
- void setLoanRate(double loanRate): changes the interest rate applied to negative balances.
- double getLoanLimit(): returns the loan limit for the account.
- void setLoanLimit(double limit): changes the loan limit for the account.
- double getOverdraftPenalty(): returns the overdraft penalty for the account.
- void setOverdraftPenalty(double penalty): changes the overdraft penalty for the account.
- void deposit(double amount): increases the balance by amount.
- boolean withdraw(double amount): if amount is less than or equal to the current balance, reduces the balance by amount and returns true. Otherwise returns false and makes no change to the balance.
- void transfer(double amount): reduces the current balance by amount.
- void processDay(): if the account balance is positive, multiplies the balance by the savings rate (divided by 365) and adds the amount to the current monthly interest. If the account balance is negative, multiplies the balance by the loan rate (divided by 365) and adds the amount to the current monthly interest. (The amount added should be negative in this case so the current monthly interest will decrease.) The processDay method represents bookkeeping that occurs at the end of each day.
- void processMonth(): adds the current monthly interest to the balance and sets the current monthly interest to zero. In addition, the overdraft penalty should be subtracted from the balance if there was ever a day in the last month in which the account balance plus the current monthly interest was negative and exceeded the negation of the loan limit. You will implement this by having a check to see if if the account balance plus the current monthly interest was negative and exceeded the negation of the loan limit at any time that processDay was called since the last time processMonth was called.
The Cash class should have a single constructor:
- It has input double savingsRate, double loanRate, double loanLimit, double overdraftPenalty and sets the savings rate, loan rate, loan limit, and overdraft penalty associated with the account.
- The Date class. The Date class will represent a date. (Java has both Date and Calendar in the API, but both are more complex than needed for this homework.) The Date class should have the following methods:
- int getDay(): returns the day of the date. The day should be a value between 1 and 31.
- int getMonth(): returns the month of the date. The month should be between 1 and 12.
- int getYear(): returns the year of the date.
- void incrementDay(): adds 1 to the day of the date. If the day exceeds the number of days for the month (assume no leap years), the day is set to 1 and the month is incremented. If the month exceeds 12, the month is set to 1 and the year is incremented.
- The Date class should override the inherited toString method to give an appropriate string representation of this date. The string should include the monthnameas well as the day and year.
- The Date class should override the inherited equals method to indicate that two Dates are equal if they are the same day, month, and year.
The Date class should have one constructor:
- It has input int day, int month, int year and initializes the Date object with the given inputs. You may assume that the inputs are all valid values.
Posted Date: