Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Done in Java Exercise - Stock Market Tracking Object O O 1. Create the stock object class to store the data for a single stock.

Done in Java

image text in transcribed

image text in transcribedimage text in transcribed

Exercise - Stock Market Tracking Object O O 1. Create the stock object class to store the data for a single stock. The data shown gives 4 instance variables to begin with - decide which data types to use for each. Use the following names for the instance variables: o symbol o stockName startingPrice previous Change 2. Write a default constructor and a 4-arg constructor for creating Stock objects. Write get/set methods for each instance variable. Write a new toString method to help with testing. Test your object class by making a Tester class and using data from the table or pdf (which has more stocks to choose from). 3. Add two new instance variables to the class: current Price, current Change where both are set to match the values of the startingPrice and previous change when an object is constructed (therefore a new 6-arg constructor is not needed). Add these to the toString method so they can be tested. Exercise - Stock Market Tracking Object 4. Write the updateStock method which takes no arguments and does not return a value. When called, the method simulates the passage of time during the trading day, where the currentPrice will be updated up/down by the current Change amount using the following formula/algorithm: x= currentChange * 15000 (truncated to make it an int; this is done so that there is a random chance that the stock will increase/decrease) r=random int 0..x OR x..0 (when x is negative if current Change is negative) o current Change = (r - x/3) / 10000 (to make it back into a double with 4-decimal-places) currentPrice = currentPrice + current Change 5. Test your new method by creating a number of Stock objects and printing out O O Exercise - Stock Market Tracking Object O O O O For example, if the stock data for Apple is used from the table (shown in italics below), and Math.random() returns 0.67890123 when the random value is calculated, then the calculations show that Apple stocks continued to increase in value by over 40 cents: x = +0.88 * 15000 = 13200 r = random value [O.. 13200) = 8961 current Change = (8961 - 13200/3)/ 10000 = +0.4561 current Price = 173.07 +0.4561 = 173.52 For example, if the stock data for Zynga is used from the table (shown in italics below), and Math.random() returns 0.1234789 when the random value is calculated, then the calculations show that Zynga stocks have turned their losses around and is now increasing slightly by 3 cents: 0 x = -0.10 * 15000 = -1500 r = random value [-1500.. 0] = -185 current Change = (-185 - (-1500/3)) / 10000 = +0.03147816 current Price = 8.96 + 0.03147816 = 8.99 O o O Avg Vol (3 month) Market Cap PE Ratio (TTM) 52 Week Range 105.603M 100.665B 35.33 9.97 25 87 46.094M 392.099B 14.34 29.57 50.08 91.635M 2.827T 30.85 116.21 182.94 59.655M 165.298B 42.22 72.50 164.46 42.724M 10.559B N/A 2.57 72.62 54.008M 194.092B 210.70 22.02 33 88 25.723M 231.499B 11.73 29.68 58.87 8.781M 32.844B N/A 33.75 66.77 Results were generated a few mins ago. Pricing data is updated frequently. Currency in USD Price Symbol Name Change % Change Volume (Intraday) Ford Motor F 25.19 +0.17 +0.68% 144.998M Company BAC Bank of America 47.91 -0.85 -1.74% 72.953M Corporation AAPL Apple Inc. 173.07 +0.88 +0.51% 80.325M Advanced Micro AMD 136.88 +4.14 +3.12% 70.088M Devices, Inc. AMC AMC Entertainment 20.57 -0.09 -0.44% 56.213M Holdings, Inc. T AT&T Inc. 27.18 +0.38 +1.42% 54.847M Wells Fargo & WFC 58.06 +2.06 +3.68% 53.944M Company Las Vegas Sands LVS 42.99 +5.33 +14.15% 49.781M Corp. ZNGA Zynga Inc. 8.96 -0.10 -1.10% 48.577M Banco Bradesco BBD 3.7700 +0.0700 +1.89% 47.3M S.A. American AAL Airlines Group 18.49 -0.85 -4.40% 44.983M Inc. Ita Unibanco ITUB 4.2500 +0.0200 +0.47% 42.794M Holding S.A. JPM JPMorgan Chase 157.89 -10.34 -6.15% 39.475M & Co. Virgin Galactic SPCE 10.14 +0.11 +1.10% 39.519M Holdings, Inc. Petrleo PBR Brasileiro S.A. 12.61 +0.31 +2.52% 39.166M Petrobras NVIDIA NVDA 269.42 +3.67 +1.38% 39.476M Corporation Microsoft MSFT 310.20 +5.40 +1.77% 39.005M Corporation Citigroup Inc. 66.93 -0.85 -1.25% 35.786M 30.661M 10.129B N/A 5.57 12.32 38.481M 36.53B 8.61 3.25 5.70 . 35.657M 11.973B N/A 15.02 26.09 42.374M 41.565B 7.91 3.55 5.57 11.347M 466.608B 9.99 127.35 172.96 12.857M 2.616B N/A . 9.75 62.90 29.771M 82.244B 3.37 7.OS 12.62 45.853M 671.395B 83.08 115.67 346.47 27.829M 2.329T 34.70 212.63 349.67 22.62M 132.807B 6.25 57.40 80.29 . NIO NIO Inc. 30.95 +0.47 +1.54% 34.863M 47.167M 49.228B N/A 27.52 84.60

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions