(Java) In this assignment you will be managing small equities portfolio made up
ID: 3883036 • Letter: #
Question
(Java) In this assignment you will be managing small equities portfolio made up of single company stocks, Exchange traded funds (ETF), and a Real Estate Investment Trust (REIT). Each object is an equity so you should have a class that is used to instansiate an equity object. The class should have the following private fields. Ticker symbol of type string Equity Name of type string Number of shares held of type integer. Equity type of type integer (0 = stock, 1 = ETF , 2 = REIT ) The Exchange of type string (NSYE, NASDQ, etc) Current equity price of type float Estimated yearly price increase in percent float . Dividend yield in percent Dividend payment cycle of type integer. (1 = Yearly, 4 = Quarterly, 12 = Monthly). Calculated Dividend amount of type float. Calculated Current value of equity of type float. Calculated value of equity after n years of type float. Methods Your class should have the following methods. 1) Public getter methods for all fields 2) Public Setter methods for all non computed fields 3) A to string method that displays the equity ticker symbol, Equity Name, Number of shares held, current price per share, Calculated current value. 4) A private method to calculate the current value of the equity. Current price * Number of shares held. 5) A private method to calculate dividend amount for each dividend payment. Dividend amount = ( current price * dividend yield) / dividend payment cycle. 6) A method to calculate the value of your equity holding after n-years. To perform this calculation you must for each year compute a new current price based on the estimated yearly price increase for n-years. This is a recurrence relation on the price. You will also need to sum up all dividend payments for over n-years and add that to the value of the equity value after n-years. 7) You should generate the following report for the portfolio. Equity ticker symbol Equity Name Equity Type ( Stock, ETF, or REIT) Equity Current price Number of shares held Current value of shares held Estimated increase in share price per year in percent. Estimated value of shares held in 5 years and 10 years. At the bottom of the report should be the total current value of all shares and the total estimated 5 year and 10 year future values of all shares held.
Data:
ticker symbol,Equity name,number of shares,Equity type,Exchange,current price,Estimated yearly price increase, dividend yield, Dividend payment cycle.
XOM,Exon Mobil Co,200,0,NYSE,76.34,4,3.35,4
D,Dominion Resources Inc,50,0,NYSE,76.41,2,3.58,4
O,Realty Income Corp.,100,2,NYSE,55.66,3.5,4.78,12
XLU,Utilities Select Sector SPDR Fund,250,1,AMEX,52.87,1.5,3.13,4
AAPL,Apple Inc,100,0,NASD,112.66,5,1.59,4
Explanation / Answer
Hi,
1. Portfolio.java
public class Portfolio {
private String tickerSymbol;
private String equityName;
private int numberOfShares;
private int equityType; // 0-stock, 1-ETF(Exchange traded funds), 2-REIT(Real Estate Investment Trust)
private String exchange;
private float currentPrice;
private float estimatedYearlyPrice;
private float dividendYield;
private int dividendPaymentCycle;// 1 = Yearly, 4 = Quarterly, 12 = Monthly
/**
* @return the current value of the equity.
*/
private float calculateCurrentValue() {
return (currentPrice * numberOfShares);
}
/**
* @return the Dividend Amount
* @param currentPrice the current price of share
*/
private float calculateDividendAmount(float currentPrice) {
float dividendAmount = (currentPrice * dividendYield) / dividendPaymentCycle;
return dividendAmount;
}
/**
* @return the EquityValueAfterNYear
* @param nYears the no of year for calculate Equity Value
*/
public float calculateEquityValueAfterNYears(int nYears) {
float total = 0;
float newCurrentPrice = currentPrice; // local new current price
for (int i = 0; i < nYears; i++) {
//total += ((newCurrentPrice * dividendYield)/dividendPaymentCycle);
total += (calculateDividendAmount(newCurrentPrice));
newCurrentPrice = newCurrentPrice + ((newCurrentPrice*estimatedYearlyPrice)/100); // calculate new current price on based on the estimated yearly price increase
}
return total;
}
@Override
public String toString() {
return tickerSymbol+","+equityName+","+numberOfShares+","+currentPrice+","+calculateCurrentValue();
}
// ======================== setters ==============================
/**
* @param tickerSymbol the tickerSymbol to set
*/
public void setTickerSymbol(String tickerSymbol) {
this.tickerSymbol = tickerSymbol;
}
/**
* @param equityName the equityName to set
*/
public void setEquityName(String equityName) {
this.equityName = equityName;
}
/**
* @param numberOfShares the numberOfShares to set
*/
public void setNumberOfShares(int numberOfShares) {
this.numberOfShares = numberOfShares;
}
/**
* @param equityType the equityType to set
*/
public void setEquityType(int equityType) {
this.equityType = equityType;
}
/**
* @param exchange the exchange to set
*/
public void setExchange(String exchange) {
this.exchange = exchange;
}
/**
* @param currentPrice the currentPrice to set
*/
public void setCurrentPrice(float currentPrice) {
this.currentPrice = currentPrice;
}
/**
* @param estimatedYearlyPrice the estimatedYearlyPrice to set
*/
public void setEstimatedYearlyPrice(float estimatedYearlyPrice) {
this.estimatedYearlyPrice = estimatedYearlyPrice;
}
/**
* @param dividendYield the dividendYield to set
*/
public void setDividendYield(float dividendYield) {
this.dividendYield = dividendYield;
}
/**
* @param dividendPaymentCycle the dividendPaymentCycle to set
*/
public void setDividendPaymentCycle(int dividendPaymentCycle) {
this.dividendPaymentCycle = dividendPaymentCycle;
}
// ======================== getters ==============================
/**
* @return the tickerSymbol
*/
public String getTickerSymbol() {
return tickerSymbol;
}
/**
* @return the equityName
*/
public String getEquityName() {
return equityName;
}
/**
* @return the numberOfShares
*/
public int getNumberOfShares() {
return numberOfShares;
}
/**
* @return the equityType
*/
public int getEquityType() {
return equityType;
}
/**
* @return the exchange
*/
public String getExchange() {
return exchange;
}
/**
* @return the currentPrice
*/
public float getCurrentPrice() {
return currentPrice;
}
/**
* @return the estimatedYearlyPrice
*/
public float getEstimatedYearlyPrice() {
return estimatedYearlyPrice;
}
/**
* @return the dividendYield
*/
public float getDividendYield() {
return dividendYield;
}
/**
* @return the dividendPaymentCycle
*/
public int getDividendPaymentCycle() {
return dividendPaymentCycle;
}
}
2. PortfolioDriver.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class PortfolioDriver {
static ArrayList<Portfolio> portfolioList = new ArrayList<>();
public static void main(String[] args) {
try {
// read Data file
Scanner input = new Scanner(new File("portfolio.txt"));
while (input.hasNextLine()) {
String line = input.nextLine();
String[] inputStrings = line.split(","); // read one line
Portfolio p = new Portfolio();
p.setTickerSymbol(inputStrings[0]);
p.setEquityName(inputStrings[1]);
p.setNumberOfShares(Integer.parseInt(inputStrings[2]));
p.setEquityType(Integer.parseInt(inputStrings[3]));
p.setExchange(inputStrings[4]);
p.setCurrentPrice(Float.parseFloat(inputStrings[5]));
p.setEstimatedYearlyPrice(Float.parseFloat(inputStrings[6]));
p.setDividendYield(Float.parseFloat(inputStrings[7]));
p.setDividendPaymentCycle(Integer.parseInt(inputStrings[8]));
portfolioList.add(p);
}
} catch (FileNotFoundException e) {
System.out.println("No such file was found");
}
report();
}
private static void report() {
for (int i = 0; i < portfolioList.size(); i++) {
// TODO: Code for report generate
// I need your help in report generate i confusion report in txt file or console so please give some more details about report method so i will update to you.
System.out.println(portfolioList.get(i).toString());
}
}
}
Let me know if any change required
thank you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.