Java Desktop App - Stock Market Simulator

From Sinfronteras
Revision as of 14:53, 12 July 2019 by Adelo Vieira (talk | contribs)
Jump to: navigation, search


Project description

In this project, we have created a GUI Java (Swing) Application that simulates a trading day of a simplified model of a stock market:

  • You can try the application by downloading the Java Jar file from this link: http://perso.sinfronteras.ws/images/0/00/SMSimulator.jar
  • You can also see or download the Java Project from our Github repository at:
  • If you just want to take a look to the Application GUI, here we show some images that try to describe the most important features of the application.


To be able to perform the simulation, the system first creates an entered number of companies with random values of <number of shares> and <share price>. Then, we create an entered number of Investors with a random <budget>.


Our simulator follows these rules toe trading day

  • If a company sells 10 shares, the share price should double up.
  • If any 10 shares are sold (from any company), and a company hasn't sold any, the price must reduce in half.
  • Investors can do as many transactions as they like, but must buy only one share per transaction. Investors must try to buy shares in as many possible companies to guarantee the safety of their investment.
  • The simulator should stop when all shares have been sold, or all investors have spent all their money.


Our Management System allows users (Zoo Administrators) to manage Animals and Zoo Keepers. Some of the functionalities that have been added to the system are:

  • Search for Animals:
Refine by: Type, Specie, Name, etc.
  • Search for Keepers
  • Add new animals to the database
  • Add new keepers
  • Update animals
Manage aspects such as Medications, Vaccines, Offsprings, etc
  • Update keepers


The most important concepts we have applied to build this applications are:

  • Design Patters:
  • GUI Java Swing
  • Inheritance, Polymorphism, Upcasting - Downcasting: These were the most important concepts we have learned and implemented in this project. Because animals are broken down into different types (see example below) we had implemented a class-based inheritance model where <Animal> is the super class. We often had to useed Downcasting in order to get access to specific behaviors of a subclass into the Animal hierarchy.
  • Abstraction
  • Encapsulation
  • Serialization: We have implemented data persistence through a file using serialization.


The Zoo has a number of Animals. These Animals are broken down into types: Mammal, Reptile, Avian, Aquatic, Insect. For example:

  • Mammal:
  • Avian
  • Bat
  • date of birth, date of arrival, fight, gender, ofspring, medication, vaccine, exhibit number



Class diagram

Class diagram1



An example of one of the classes

public class Test {
    
    public static void main(String[] args) {
        Cat c = new Cat();
        System.out.println(c.health);
        
        Dog d = new Dog();
        System.out.println(d.health);
        
        
        // // Upcasting
        Mammal m = c;           // Although there's no need to for programmer to upcast manually, it's legal to do so:
                                // Mammal m = (Mammal) new cat();
                                
        System.out.println(c);  // This print:               upcastingdowncasting.Cat@15db9742                               
        System.out.println(m);  // This will print the same: upcastingdowncasting.Cat@15db9742
                                // As you can see, Casting does not change the actual object type
                                // Cat is still exactly the same Cat after upcasting.
                                // It didn't change to a Mammal, it's just being labelled Mammal right now.
                                // This is allowed, because Cat is a Mammal.
        
                                        
        // // Downcasting
        if(m instanceof Cat){   // testing if the Animal is a Cat
            System.out.println("It's a Cat! Now I can downcast it to a Cat, without a fear of failure.");
            Cat c1 = (Cat)m;    // Manual downcasting back to a Cat
        }
        
        // The following code will compile, but throws "java.lang.ClassCastException: Mammal cannot be cast to Cat" exception during runTime,
        // because I’m trying to cast a Mammal, which is not a Cat, to a Cat.
        Mammal m1 = new Mammal();
        Cat    c2 = (Cat)m1;                        
                                
    }
    
}



A look at the GUI



Assignment Introduction

You have been asked to design and implement a simulator of a simplified model of a stock market.

The program is going to simulate both companies and investors, following the specific requirements described below.

When the simulation has been completed, you must present the user a menu with a list of possible reports for them to see the result.



Specific Requirements

  • The system must create dynamically 100 companies. All of them must have:
  • A unique ID
  • A random number of shares (between 500 and 1000)
  • A random share price (between 10 and 100)
  • Any other attribute that you consider relevant to the context


  • The system must create dynamically 100 investors. All of them must have:
  • A unique ID
  • Arandom budget between 1000 and 10000
  • Any other attribute that you consider relevant to the context


  • Once all the companies have been created, the simulator should run a "trading day". This will run transactions were investors buy shares in the companies that exist, following the rules below:
  • If a company sells 10 shares, the share price should double up.
  • If any 10 shares are sold (from any company), and a company hasn't sold any, the price must reduce in half.
  • Investors can do as many transactions as they like, but must buy only one share per transaction. Investors must try to buy shares in as many possible companies to guarantee the safety of their investment.
  • The simulator should stop when all shares have been sold, or all investors have spent all their money.


  • You are required to present the user with a menu to display the result of the simulation, with the following options:
  • Company with the highest capital(number of shares times share price).
  • Company with the lowest capital (number of shares times share price).
  • If there are more than one company at the top or bottom position, they all should be displayed in the result.
  • Investor with the highest number of shares.
  • Investor that has invested in the most companies.
  • Investor with the lowest number of shares.
  • Investor that has invested in the least number of companies.
  • It there is more than one investor in any of the positions, they all should be displayed in the result.


  • At least three design patterns must be implemented in your project.



Extra marks

If you would like to achieve a distinction consider adding some extra layers of functionality, such as, but not limited to:

  • Implementing data persistency through a file or external database, or any other aspect that might be relevant to the context.
  • Implementation of a multi threaded environment to simulate several investors trading at the same time.
  • Other reports such as total number of transactions.