Avatar billede salimbharuchi Nybegynder
10. oktober 2009 - 22:22 Der er 7 kommentarer

A game where a player can earn (or loose) money by buying and selling goods.

A game where a player can earn (or loose) money by buying and selling goods.

At the start of the game, the player has a fixed amount of money available, say 1000 Euro.  The money can be used for buying goods of a number of kinds, say two kinds, steel and sugar.  The number of kinds of goods is fixed.  At every round of the game the price of each good change and the player earns money by buying goods when the price is low and selling the goods again when the price is high.

At every round the actual prices of the goods have to be available to the player such that he/she can judge whether the round is appropriate for selling or buying a certain good.  At every round the player is charged a fee for stocking of the goods he/she has bought.  For each good, the fee per round is the number of kilos in stock of the good times a fee per kilo. The player has to be able to choose when he/she wants to continue the next round and when he/she wants to stop the game. For each round the program has to calculate a new price for each kind of good and it has to calculate the total fee for stocking and, if possible, deduct the amount from the money of the player. If the player does not have enough money to pay the fee, then the program has to stop the game and declare the player bankrupt. The solution has to involve exactly three classes:

GameTest
This class contains the main method. The only thing the main method does is to generate a Game object and start the game by calling an appropriate method in the Game object.

Game
given that there has to be two kinds of goods; a Game object has to involve two objects for the class Good. A Game object can for example also keep track of how much money the player has.

Good
every good involves at least a name and a price. A random variation of the price is calculated every round such that the development of the price exhibits an increasing trend.

Some Remarks:
Interaction with the player is expected to take place by printing to the screen and reading via the command prompt or dialog boxes. To generate the random variation of prices, java's class random has to be used. The solution must NOT involve array list or arrays.

****************************************************************
So far i only have three classes as mentioned above GameTest, Game and Good..
Avatar billede Slater Ekspert
11. oktober 2009 - 00:08 #1
So... what's the question?
Avatar billede salimbharuchi Nybegynder
11. oktober 2009 - 00:30 #2
the question is whats described above, I need to create a game in JAVA where a player can earn (or loose) money by buying and selling goods, which runs thru console..

Hope this helps..
Avatar billede arne_v Ekspert
12. oktober 2009 - 23:51 #3
I doubt that anyone will be willing to write your entire program.

And they should not either, because you will not learn much from that.

So start writing some code and post snippets with questions when you run into problems.
Avatar billede salimbharuchi Nybegynder
18. oktober 2009 - 21:55 #4
Yes arne you are absolutely right..i never intended to ask for entire program..i wasnt able to get the start thats the reason i posted the entire program help...but now atleast i got the start...here's what i have so far...

***************************'Good Class*********'
import java.util.Random;

public class Good
{
       
        private int Steel;
        private int Sugar;
        private Random generator;
       
       
        public Good(int st, int su)
        {
            Steel = st;
            Sugar = su;
            generator = new Random();
        }
        public int getSteel()
        {
            return 1 + generator.nextInt(Steel);

        }
        public int getSugar()
        {
            return 1 + generator.nextInt(Sugar);

        }
}

******************Game class********'


public class Game
{
       
    private int money;
    private int balance;
   
    Good g = new Good(100,100);
    int newPriceSteel = g.getSteel();
    int newPriceSugar = g.getSugar();
       
    public Game(int bal)
    {
        money = 1000;
        bal = money;
        balance = bal;
    }
}

Can you please guide me further in my game class...
Avatar billede Anna Kena Praktikant
03. juni 2024 - 09:50 #5
Sounds like a thrilling game of financial strategy, not unlike the infamous rice purity test. I wonder how one's 'purity score' would fare in the cutthroat world of virtual commerce. Regardless, it seems like a fun way to test one's mettle - and wallet!
Avatar billede samcoffee Praktikant
23. august 2024 - 09:36 #6
It sounds like an exciting game of financial strategy, reminiscent of navigating risky investments. I’m curious what a sex dolls cheap would look like in the fierce world of virtual business. Either way, it seems like an entertaining way to challenge both your wits and your wallet!
Avatar billede begali2875 Praktikant
Skrevet i dag kl. 12:33 #7
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester