• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Stock Portfolio

 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Can anyone help Lloyd?
[ July 16, 2003: Message edited by: Marilyn de Queiroz ]
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops. The assignment got lost somewhere in the posting.

Stock Portfolio
Develop an application that allows users to "play the stock market." Users will be able to buy and sell stock, and find out the value of each stock as well as the value of their portfolio. Stock prices will fluctuate. This application will be developed in stages.

In stage I, you will create the Stock class that will have instance variables of name, purchase price, number of shares, and current price. You will need methods to gain access to the instance variables and method to randomly adjust stock prices up or down (generate a random number between -I and + I and multiply that value by the price per share and assign it to a variable called current price). A main() method can also be included for testing. There should be at least 9 methods for this class. The name of the class will be Stock.
In another class called PlayStock the main() method is where you should ask the user the name, purchase price and number of shares. Next, you will simulate the fluctuation of stock prices by increasing or decreasing the stock price randomly. After adjusting the price, print the stock name, purchase price, number of shares and current price. The main() method should also calculate and display the value of the stock by multiplying the number of shares by the current price, how much it was when purchased and the gain or loss (a positive number is a gain and a negative number is a loss).
To convert your stock names to upper case, use the toUpperCase() method of the String class. To round your decimal values, use the format() method of the DecimalFormat class.
[ July 16, 2003: Message edited by: Marilyn de Queiroz ]
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In stage I, you will create the Stock class that will have instance variables of name, purchase price, number of shares, and current price. You will need methods to gain access to the instance variables and method to randomly adjust stock prices up or down (generate a random number between -I and + I and multiply that value by the price per share and assign it to a variable called current price). A main() method can also be included for testing. There should be at least 9 methods for this class. The name of the class will be Stock.

The class name is Stock. Good start, Lloyd.

I suggest that "name" should be a String, "purchasePrice" should be a double, "numberOfShares" should be an int (since you can't buy a fraction of a share), and "currentPrice" should be another double.

"methods to gain access to the instance variables" are usually called something like getName(), getPurchasePrice() etc. which return the variable. (That's already 4 methods) These types of methods are usually pretty straightforward.

You need a method to generate a random number. This one may take a little more research to fulfill the requirements stated above.

And your main method. So you only need three more methods.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In another class called PlayStock the main() method is where you should ask the user the name, purchase price and number of shares.

How are you going to get the input from the user?

Next, you will simulate the fluctuation of stock prices by increasing or decreasing the stock price randomly.

Here's the random stuff again.

After adjusting the price, print the stock name, purchase price, number of shares and current price.

Printing. That's pretty easy.

The main() method should also calculate and display the value of the stock by multiplying the number of shares by the current price, how much it was when purchased and the gain or loss (a positive number is a gain and a negative number is a loss).

Calculations. Also pretty easy. Multiplication, addition, subtraction. Is the result greater than or less than zero?
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic