Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Stock { // Private variables private int inumshares; private double dPrice; private String sTicker; private String sCompanyName; private double dValueofheldshares; // Consturctors Stock()

image text in transcribed

image text in transcribed

public class Stock { // Private variables private int inumshares; private double dPrice; private String sTicker; private String sCompanyName; private double dValueofheldshares; // Consturctors Stock() { inumshares=0; dPrice=0.0; sTicker=""; sCompanyName=""; dValueofheldshares=0.0; } Stock(String TickerSymbol, String Tickername, int Sharesheld, double Price) { sTicker=TickerSymbol; sCompanyName=Tickername; inumshares=Sharesheld; dPrice=Price; dValueofheldshares = inumshares * dPrice; } // Public getters public int getinumshares() { return inumshares; } public double getdPrice() { return dPrice; } public String getsTicker() { return sTicker; } public String getsCompanyName() { return sCompanyName; } public double getdValueofheldshares() { return dValueofheldshares; } // public setters void setinumshares(int numsharesheld) { inumshares = numsharesheld; } void setdPrice(double Price) { dPrice=Price; } void setsTicker(String Ticker) { sTicker=Ticker; } void setsCompanyName(String CompanyName) { sCompanyName=CompanyName; } // Public updaters void UpdateValueofShares() { dValueofheldshares = inumshares * dPrice; } // Public toString. public String toString() { String RetString="Ticker: "; RetString=RetString.concat(sTicker); RetString=RetString.concat(" Company: "); RetString=RetString.concat(sCompanyName); RetString=RetString.concat(" Number of Shares: "); RetString=RetString.concat(String.valueOf(inumshares)); RetString=RetString.concat(" Price Per Share: "); RetString=RetString.concat(String.valueOf(dPrice)); RetString=RetString.concat(" Total value: "); RetString=RetString.concat(String.valueOf(dValueofheldshares)); RetString=RetString.concat(" "); return RetString; } }

---------------------------------------------------------------------------------------------------------------------------------------

/* CSC 202 Assignment 3, Hunter Frostick * * Equity Report * * Yahoo Finance API */ public class YahooFinanceAPI { /ew instance variables private String tickerSymbol; private int equityType; private int sharesHeld; /ew constructor YahooFinanceAPI() { tickerSymbol = ""; equityType = 0; sharesHeld = 0; } /ew parameters to the new constructor YahooFinanceAPI(String TickerSymbol, int EquityType, int Sharesheld) { tickerSymbol = TickerSymbol; equityType = EquityType; sharesHeld = Sharesheld; } /ew public getters public String getTickerSymbol() { return tickerSymbol; } public int getEquityType() { return equityType; } public int getSharesHeld() { return sharesHeld; } /ew public setters void setTickerSymbol(String TickerSymbol) { tickerSymbol = TickerSymbol; } void setEquityType(int EquityType) { equityType = EquityType; } void setSharesHeld(int SharesHeld) { sharesHeld = SharesHeld; } /ew public toString method public String toString() { String RetString = "Ticker Symbol: "; RetString = RetString.concat(tickerSymbol); RetString = RetString.concat(" Equity Type: "); RetString = RetString.concat(String.valueOf(equityType)); RetString = RetString.concat(" Shares Held: "); RetString = RetString.concat(String.valueOf(sharesHeld)); return RetString; } }

------------------------------------------------------------------------------------------------------------------------------------

import java.util.*; public class YahooFinanceAPITester { public static void main(String[] args) { //constructor Stack st = new Stack(); //used for testing the YahooFinanceAPI Class //push equities onto the stack //equity ticker symbol, equity type (0 = Stock, 1 = ETF, or 2 = REIT), and the number of shares held st.push(new YahooFinanceAPI("XOM", 0, 81.34)); st.push(new YahooFinanceAPI("D", 0, 73.41)); st.push(new YahooFinanceAPI("O", 2, 45.66)); st.push(new YahooFinanceAPI("XLU", 1, 47.87)); st.push(new YahooFinanceAPI("AAPL", 0, 112.66)); //if stack is not empty, use peek to view the contecnts of the stack if( !st.empty()) { YahooFinanceAPI EQTop = (YahooFinanceAPI)st.peek(); System.out.print(EQTop.toString()); } else System.out.println("Stack is empty."); //pop each object off the stack and display the objects contents System.out.println("Pop the stock objects off the stack and display the contents of the objects."); while( !st.empty() ) { YahooFinanceAPI EQpop = (YahooFinanceAPI)st.pop(); System.out.print(EQpop.toString()); } } }

----------------------------------------------------------------------------------------------------------------------------------------

I cannot get it to compile, please help!

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 (stock, 1 Number of shares held of type integer. ETF, 2 REIT) 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions