Question: CSC-202 Assignment-3 Fall-2017 In this assignment you will be modifying the class you created in assignment-1. The first modification will be to add a new
CSC-202 Assignment-3 Fall-2017 In this assignment you will be modifying the class you created in assignment-1. The first modification will be to add a new constructor that will accept three inputs, 1 the ticker symbol, 2 the Equity type (0 = stock, 1 = ETF , 2 = REIT ) and 3, total number of shares held. The constructor will then do an internet call and use the Yahoo Finance API to get information into the object. We will discuss in class the example code posted that shows you how do to this. Again you will use the same class you created in assignment 1 adding the new constructor. You may have to add some new private variables and the associated getters and setters. The variables that you pass into the new constructor are Ticker symbol of type string Equity type of type integer (0 = stock, 1 = ETF , 2 = REIT ) Number of shares held of type integer. The variables whose values will be set by retrieving the information over the internet using the Yahoo Finance API are Equity Name of type string Yahoo Finance API flag - n The Exchange of type string (NSYE, NASDQ, etc) - Yahoo Finance API flag - x Current equity price of type float - Yahoo Finance API flag b Price at market open type float - Yahoo Finance API flag o Previous close price type float - Yahoo Finance API flag -p Dividend yield in percent of type float - Yahoo Finance API flag - y Dividend amount of type float. - Yahoo Finance API flag d Note; not calculated in this case. Dividend pay rate type float - Yahoo Finance API flag r1 Last trade date if type string - Yahoo Finance API flag d1 Fifty two week high price float - Yahoo Finance API flag k Fifty two week low price float - Yahoo Finance API flag - j Your main program will create an array of objects where each array element is an instance of one of the equities. Your main program should then use that array to generate the following report. At the top of the report put our class CSC-202 FAll 2017 Assignment-3 and your name. The next line should be blank followed by a line that says Equity report followed by a report that contains the following information for each equity in the array. Equity ticker symbol Equity Name Exchange the equity is traded on. Equity Type ( Stock, ETF, or REIT) Equity Current price Equity price at the open Previous close price. 52 week range High price low price Dividend yield Dividend amount Dividend pay rate Last trade date (Format mm/dd/yyyy) Number of shares held Current value of shares held ( = Equity Current price * number of shares ). Upload your source code (Equity class and main driver) for grading.
----------------------------------
/** * Portfolio class * */ public class Portfolio { public static void main(String[] args) { System.out.println("Hunter Frostick"); System.out.println("CSC 202"); System.out.println("EQUITY REPORT"); System.out.println("");
Portfoliocalc p1 = new Portfoliocalc("XOM", 0, 200);
Portfoliocalc p2 = new Portfoliocalc("D", 0, 50);
Portfoliocalc p3 = new Portfoliocalc("O", 2, 100);
Portfoliocalc p4 = new Portfoliocalc("XLU", 1, 250);
Portfoliocalc p5 = new Portfoliocalc("AAPL", 0, 100);
Portfoliocalc[] portfolios = { p1, p2, p3, p4, p5 };
for (int i = 0; i < portfolios.length; i++) { printPortfolio(portfolios[i]); } }
public static void printPortfolio(Portfoliocalc p) { System.out.println("Equity ticker symbol\t\t\t:" + p.getTickerSymbol()); System.out.println("Equity name\t\t\t\t:" + p.getEquityName()); System.out.println("Exchange\t\t\t\t:" + p.getExchange()); System.out.println("Equity type\t\t\t\t:" + p.getEquityType()); System.out.println("Equity Current price\t\t\t\t:" + p.getCurrentEquityPrice()); System.out.println("Price at open\t\t\t\t:" + p.getPriceAtMarketOpen()); System.out.println("Previous close price\t\t\t\t:" + p.getPreviousClosePrice()); System.out.println("52 week range\t\t\t\t:" + p.getFiftyTwoWeekHighPrice() + "-" + p.getFiftyTwoWeekLowPrice()); System.out.println("Dividend yield\t\t\t\t:" + p.getDividendYieldPercent()); System.out.println("Dividend amount\t\t\t\t:" + p.getDividendAmount()); System.out.println("Dividend pay rate\t\t\t\t:" + p.getDividendPayRate()); System.out.println("Last trade date\t\t\t\t:" + p.getLastTradeDate()); System.out.println("Number of shares held\t\t\t:" + p.getNumberOfSharesHeld()); System.out.println("Current value of shares held\t\t\t:" + p.getCurrentValueOfEquity()); System.out.println(); } }
--------------------------------------------------------------------------------------------------
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.Scanner;
/** * Portfoliocalc class * */
public class Portfoliocalc { // data members private String tickerSymbol; private String equityName; private int numberOfSharesHeld; private int equityType; private String exchange; private double currentEquityPrice; private double priceAtMarketOpen; private double estimatedYearlyPriceIncreasePercent; private double dividendYieldPercent; private double dividendPaymentCycle; private double dividendAmount; private double currentValueOfEquity; private double equityAfterNYears; private double previousClosePrice; private String dividendPayRate; private String lastTradeDate; private double fiftyTwoWeekHighPrice; private double fiftyTwoWeekLowPrice;
/** * Constructor */ public Portfoliocalc() {
this.tickerSymbol = "N/A"; this.equityName = "N/A"; this.numberOfSharesHeld = -1; this.equityType = -1; this.exchange = ""; this.currentEquityPrice = -1; this.setPriceAtMarketOpen(-1); this.estimatedYearlyPriceIncreasePercent = -1; this.dividendYieldPercent = -1; this.dividendPaymentCycle = -1;
}
/** * @paramtickerSymbol * @paramequityName * @paramnumberOfSharesHeld * @paramequityType * @paramexchange * @paramcurrentEquityPrice * @param priceAtMarketOpen * @param estimatedYearlyPriceIncreasePercent * @param dividendYieldPercent * @param dividendPaymentCycle * @param dividendAmount * @param currentValueOfEquity * @param equityAfterNYears * @param previousClosePrice * @param dividendPayRate * @param lastTradeDate * @param fiftyTwoWeekHighPrice * @param fiftyTwoWeekLowPrice */ public Portfoliocalc(String tickerSymbol, String equityName, int numberOfSharesHeld, int equityType, String exchange, double currentEquityPrice, double priceAtMarketOpen, double estimatedYearlyPriceIncreasePercent, double dividendYieldPercent, double dividendPaymentCycle, double dividendAmount, double currentValueOfEquity, double equityAfterNYears, double previousClosePrice, String dividendPayRate, String lastTradeDate, double fiftyTwoWeekHighPrice, double fiftyTwoWeekLowPrice) { this.tickerSymbol = tickerSymbol; this.equityName = equityName; this.numberOfSharesHeld = numberOfSharesHeld; this.equityType = equityType; this.exchange = exchange; this.currentEquityPrice = currentEquityPrice; this.priceAtMarketOpen = priceAtMarketOpen; this.estimatedYearlyPriceIncreasePercent = estimatedYearlyPriceIncreasePercent; this.dividendYieldPercent = dividendYieldPercent; this.dividendPaymentCycle = dividendPaymentCycle; this.dividendAmount = dividendAmount; this.currentValueOfEquity = currentValueOfEquity; this.equityAfterNYears = equityAfterNYears; this.previousClosePrice = previousClosePrice; this.dividendPayRate = dividendPayRate; this.lastTradeDate = lastTradeDate; this.fiftyTwoWeekHighPrice = fiftyTwoWeekHighPrice; this.fiftyTwoWeekLowPrice = fiftyTwoWeekLowPrice; }
/** * @param tickerSymbol * @param equityType * @param numberOfSharesHold */ public Portfoliocalc(String tickerSymbol, int equityType, int numberOfSharesHold) { this.tickerSymbol = tickerSymbol; this.equityType = equityType; this.numberOfSharesHeld = numberOfSharesHold; String queryURLString = "http://finance.yahoo.com/d/quotes.csv" + tickerSymbol + "&f=nxbopydr1d1kj&e=.csv"; // query // url try { URL queryURL = new URL(queryURLString); HttpURLConnection con = (HttpURLConnection) queryURL.openConnection(); con.setRequestMethod("GET"); BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream())); String input; String[] output; input = reader.readLine(); // System.out.println(input); output = input.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1); this.equityName = output[0]; this.exchange = output[1]; this.currentEquityPrice = Double.parseDouble(output[2]); this.setPriceAtMarketOpen(Double.parseDouble(output[3])); this.setPreviousClosePrice(Double.parseDouble(output[4])); this.dividendYieldPercent = Double.parseDouble(output[5]); this.dividendAmount = Double.parseDouble(output[6]); this.setDividendPayRate(output[7]); this.setLastTradeDate(output[8]); this.setFiftyTwoWeekHighPrice(Double.parseDouble(output[9])); this.setFiftyTwoWeekLowPrice(Double.parseDouble(output[10])); reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * @return ticker symbol */ public String getTickerSymbol() { return tickerSymbol; }
/** * @return equity name */ public String getEquityName() { return equityName; }
/** * @return number of shares hold */ public int getNumberOfSharesHeld() { return numberOfSharesHeld; }
/** * @return equity type */ public int getEquityType() { return equityType; }
/** * @return exchage name */ public String getExchange() { return exchange; }
/** * @return current equity price */ public double getCurrentEquityPrice() { return currentEquityPrice; }
/** * @return Estimated Yearly Price Increase Percent */ public double getEstimatedYearlyPriceIncreasePercent()
{ return estimatedYearlyPriceIncreasePercent; }
/** * @return Dividend Yield Percent */ public double getDividendYieldPercent() { return dividendYieldPercent; }
/** * @return Dividend Payment Cycle */ public double getDividendPaymentCycle() { return dividendPaymentCycle; }
/** * @return Dividend Amount */ public double getDividendAmount() { return dividendAmount; }
/** * @return Current Value Of Equity */ public double getCurrentValueOfEquity() { calculateCurrentValueOfEquity(); return currentValueOfEquity; }
/** * @return Equity After N Years */ public double getEquityAfterNYears() { return equityAfterNYears; }
/** * @param tickerSymbol */ public void setTicketSymbol(String tickerSymbol) { this.tickerSymbol = tickerSymbol; }
/** * @param equityName */ public void setEquityName(String equityName) { this.equityName = equityName; }
/** * @param numberOfSharesHeld */ public void setNumberOfSharesHeld(int numberOfSharesHeld) { this.numberOfSharesHeld = numberOfSharesHeld; }
/** * @param equityType */ public void setEquityType(int equityType) { this.equityType = equityType; }
/** * @param exchange */ public void setExchange(String exchange) { this.exchange = exchange; }
/** * @param currentEquityPrice */ public void setCurrentEquityPrice(double currentEquityPrice) { this.currentEquityPrice = currentEquityPrice; }
/** * @param estimatedYearlyPriceIncreasePercent */ public void setEstimatedYearlyPriceIncreasePercent(double estimatedYearlyPriceIncreasePercent) { this.estimatedYearlyPriceIncreasePercent = estimatedYearlyPriceIncreasePercent; }
/** * @param dividendYieldPercent */ public void setDividendPercent(double dividendYieldPercent) { this.dividendYieldPercent = dividendYieldPercent; }
/** * @param dividendPaymentCycle */ public void setDividendPaymentCycle(double dividendPaymentCycle) { this.dividendPaymentCycle = dividendPaymentCycle; }
/* * (non-Javadoc) * * @see java.lang.Object#toString() */ public String toString() { String result = ""; result += "Equity ticker symbol : " + getTickerSymbol() + " "; result += "Equity name : " + getEquityName() + " "; result += "Number of shares held : " + getNumberOfSharesHeld() + " "; result += "Current price per share : " + getCurrentEquityPrice() + " "; result += "Calculated current value : " + getCurrentValueOfEquity() + " "; return result; }
/** * calculate current value of equity */ @SuppressWarnings("unused") private void calculateCurrentValueOfEquity() { currentValueOfEquity = getCurrentEquityPrice() * getNumberOfSharesHeld(); }
/** * calculate dividend amount */ @SuppressWarnings("unused") private void calculateDividendAmount() { dividendAmount = (getCurrentEquityPrice() * getDividendYieldPercent()) / getDividendPaymentCycle(); }
/** * calculate equity amount after N years. */ public void calculateEquityAfterNYears() { equityAfterNYears = getCurrentEquityPrice(); for (int i = 1; i < dividendPaymentCycle; i++) { equityAfterNYears += equityAfterNYears * estimatedYearlyPriceIncreasePercent; } }
/** * @return the priceAtMarketOpen */ public double getPriceAtMarketOpen() { return priceAtMarketOpen; }
/** * @param priceAtMarketOpen * the priceAtMarketOpen to set */ public void setPriceAtMarketOpen(double priceAtMarketOpen) { this.priceAtMarketOpen = priceAtMarketOpen; }
/** * @return the previousClosePrice */ public double getPreviousClosePrice() { return previousClosePrice; }
/** * @param previousClosePrice * the previousClosePrice to set */ public void setPreviousClosePrice(double previousClosePrice) { this.previousClosePrice = previousClosePrice; }
/** * @return the dividendPayRate */ public String getDividendPayRate() { return dividendPayRate; }
/** * @param dividendPayRate * the dividendPayRate to set */ public void setDividendPayRate(String dividendPayRate) { this.dividendPayRate = dividendPayRate; }
/** * @return the lastTradeDate */ public String getLastTradeDate() { return lastTradeDate; }
/** * @param lastTradeDate * the lastTradeDate to set */ public void setLastTradeDate(String lastTradeDate) { this.lastTradeDate = lastTradeDate; }
/** * @return the fiftyTwoWeekHighPrice */ public double getFiftyTwoWeekHighPrice() { return fiftyTwoWeekHighPrice; }
/** * @param fiftyTwoWeekHighPrice * the fiftyTwoWeekHighPrice to set */ public void setFiftyTwoWeekHighPrice(double fiftyTwoWeekHighPrice) { this.fiftyTwoWeekHighPrice = fiftyTwoWeekHighPrice; }
/** * @return the fiftyTwoWeekLowPrice */ public double getFiftyTwoWeekLowPrice() { return fiftyTwoWeekLowPrice; }
/** * @param fiftyTwoWeekLowPrice * the fiftyTwoWeekLowPrice to set */ public void setFiftyTwoWeekLowPrice(double fiftyTwoWeekLowPrice) { this.fiftyTwoWeekLowPrice = fiftyTwoWeekLowPrice; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
