• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Is there any way to write this code more simple?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating stock market simulation game for my project. I need help to make this code short.
 
author
Posts: 23923
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

First, do you really need the player1, player2, player3, etc. variables?  Can't you use the array directly? .... like playList[0], playList[1], playList[2]?

If you don't need them (and use the array directly), you can get rid of a lot of variable declarations.

Henry
 
Marshal
Posts: 8300
592
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Erdene Yadam wrote:

Why have you declared them as static?
Don't call them bankList..., *list, while they are actually arrays. List is a different data structure.

Erdene Yadam wrote:I need help to make this code short.

Why such requirement? How about correctness of your simulation game? All good already? It isn't. Your program structure is wrong. Would you like to tell a bit more about project, maybe share instructions, so we could give some better advises rather than how to shorten the code. Question would have been liked more if it were "How to add more clarity to my program?"

 
Liutauras Vilda
Marshal
Posts: 8300
592
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Erdene Yadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for a reply.
Instructions for this project.
You are to create a stock market simulation game, which has many of the characteristics of real electronic
commerce. The entities in the game are a bank, a stock exchange, and several companies and players.
Bank: The bank holds the money of one customer (one player or company). A customer can open a new
account, and deposit and withdraw money from the account. Once every 10 seconds during the game, all
money in an account accumulates interest. The interest for the customers with the highest and second
highest amount of money is 5%, while the interest for the other customers is 3%.
Company: A company has a name and can issue stock. Initially each company has 1000 shares of stock,
which starts at $30 a share. A company buys or sells shares to a player by accepting or rejecting the player's
bid.
Player: A player initially has $2000 in the bank, and buys and sells stock from companies or other players
by trading through the stock exchange. The goal of a player is to make money. A player buys or sells shares
from other players or companies by posting bids on the stock through stock exchange.
Stock Exchange: All trading of stocks must go through the centralized stock exchange. For each stock that
is being selling, the stock exchange posts the latest transaction of that stock if possible. The stock exchange
also displays the information of each bidder (the bidding price and name of the player/company). The stock
exchange stores the stock transaction information in a txt file.
Suppose we have three companies and five players in our game. When the players or companies want to
sell the stocks is random, the number of the stocks to be sold is also random. At any time point, we have at
most one type of stock that is being selling. For a stock, the number of bidders is random. One company or
player may accept or reject other players' or companies' bids. The bidding price of each player or company
could be random, you can also manually enter the price yourself if you want. After all bidders place the bid,
if the highest bidding price is no less than 0.9 * the price of the latest transaction of that stock, then the play
or company accepts the bid; otherwise, the player or company rejects the bid. If a stock is being selling for
the first time, whether the selling player or company accepts the highest bidding price is random (the
highest bidding price should not be zero). You should try to generate the corresponding random number
within the reasonable range. For example, we have three companies and five players, if one company or
player plan to sell the stocks, then the number of bidders should be within the range [0, 7]. Let your
program run some time (30 seconds for example) and see which player wins the game.
 
Liutauras Vilda
Marshal
Posts: 8300
592
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That might be a bit more interesting than we see usually. Will read it later tonight. Not sure how much you have accomplished that assignment, but if not much I'd suggest to draw a clear diagram, as it is quite a lot information to perceive in the head as a whole.

What classes along with relevant methods you have created and tested already?
 
reply
    Bookmark Topic Watch Topic
  • New Topic