Question
need code for this in java

Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes:
-To know the customer id, customer name, the broker for the customer (which is an object from the Broker class), the availabl
classes collaborate together to simulate a stock transaction system. For example: You may need more than the following two op
the arraylist of stocks at that stock market 2. when a customer initializes a stock purchasing through a broker, an object of
Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on a stock market. The class's responsibilities are as follows: -To know the name, location, the stock (an object from the Stock class)and total number of shares released of the company, as well as the arraylist of customers holding the stock. 3. the Stock class: this class simulates a stock. The class's responsibilities are as follows: To know the symbol, price of the stock 4. The Customer class: This class should simulate a customer that performs a stock transaction. The class's responsibility are as follows:
-To know the customer id, customer name, the broker for the customer (which is an object from the Broker class), the available cash balance. It also has an arraylist of stocks holding by this customer and the number of shares for that stock. 5. The Broker class: This class should simulate a broker. The class's responsibility are as follows: To know the broker license number, broker name, the total commissions (2% of the transaction amount) for the broker. It also has an arraylist of customers served by this broker and an arraylist of stock transactions (which are objects from Transaction class) performed by this broker. 6. The Transaction class: This class should simulate a stock transaction. The class's responsibility are as follows -To know the transaction id, transaction type (buy/sell), transaction stock (an object from the Stock class), transaction price, broker for the transaction (object from the Broker class), customer for the transaction (object from the Customer class). For each class, define proper data fields, getters and setters, as well as other required methods. Write a program that demonstrate how these
classes collaborate together to simulate a stock transaction system. For example: You may need more than the following two operations 1. when a company IPO at a stock market, a corresponding Stock object should be created for that company, and a stock should also be added to the arraylist of stocks at that stock market 2. when a customer initializes a stock purchasing through a broker, an object of the Transaction class should be created. For the broker: the total commission, the arraylist of the broker's customers, the arraylist of transactions performed by the broker should be updated. For the customer, the cash balance, the stock holding positions should be updated. Hints: 1. The data fields/properties/attributes of a class are the things a class should know 2. Any behavior or action of a class should be defined as methods of that class 3. Data security of aggregation is done through copy constructor
the arraylist of stocks at that stock market 2. when a customer initializes a stock purchasing through a broker, an object of the Transaction class should be created. For the broker: the total commission, the arraylist of the broker's customers, the arraylist of transactions performed by the broker should be updated. For the customer, the cash balance, the stock holding positions should be updated. Hints: 1. The data fields/properties/attributes of a class are the things a class should know 2. Any behavior or action of a class should be defined as methods of that class 3. Data security of aggregation is done through copy constructor
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import util.*;
import util.Iterator;
// We are importing the contnents of the util library
public class StockMarket
{

Map<String,DatedValue<Double,Date>> stockMarket;
//these are all private and static members as they have their infulence over the entirety of application
static final Date END_OF_TIME = new Date( Long.MAX_VALUE );
static Date[] d;static Random r = new Random( 1 );
static final int NUM_DATES = 100;
static
{
Calendar calendar = Calendar.getInstance();
calendar.set( 2003, 1, 1 );
d = new Date[NUM_DATES];
for( int i = 0; i < NUM_DATES; )
{
calendar.add( Calendar.DAY_OF_MONTH, 1 );
int day = calendar.get( Calendar.DAY_OF_WEEK );
if( day == Calendar.SATURDAY || day == Calendar.SUNDAY )
continue;
Date date = calendar.getTime();
d[i] = date;
i++;
}
}
  
/**
* Creates a new instance of StockExample
*/
public StockExample()
{
initializeStockMarket();
}
  
  
private void initializeStock( String stock, double initialValue )
{
// stock prices vary over time, so use a dated value
DatedValue<Double,Date> values = new ValueByDate<Double,Date>();
  
// add the stock to the stock market
stockMarket.put( stock, values );
  
// set the stock prices
double value = initialValue;
for( int i = 0; i < d.length - 1; i++ )
{
values.set( Double.valueOf( value ), d[i], d[i+1] );
double change = r.nextDouble();
value += change < 0.6? -change : change;
if( value < 0.0 )
value = 0.0;
}
}
  
/**
* Initializes the stock market with three fictitious companies.
*/
private void initializeStockMarket()
{
stockMarket = new HashMap<String,DatedValue<Double,Date>>();
  
initializeStock( "Global Software For Geeks", 100.00 );
initializeStock( "Compewter Materials", 50.00 );
initializeStock( "Mice With Wheels", 10.50 );
}
  
/**
* Returns the value of the specified stock at the specified date.
*/
private double lookupStockPrice( String stock, Date date )
{
DatedValue<Double,Date> values = stockMarket.get( stock );
if( values == null )
throw new NoSuchElementException();
  
Double value = values.get( date );
assert value != null;
  
return value.doubleValue();
}

/**
* Calculates and returns the value of the specified portfolio at the
* specified date.
*/
private double getPortfolioValue( DatedMap<String,Integer,Date> portfolio, Date date )
{
double total = 0.0;
  
// for each entry in the dated map
DatedSet<DatedMap.Entry<String,Integer,Date>,Date> entrySet = portfolio.entrySet();
Iterator<DatedMap.Entry<String,Integer,Date>,Date> iter = entrySet.iterator( date );
while( iter.hasNext() )
{
DatedMap.Entry<String,Integer,Date> entry = iter.next();
  
// what stock is it?
String stock = entry.getKey();
  
// for how many shares?
Integer shares = entry.getValue();
  
// look up the value
double price = lookupStockPrice( stock, date );
double value = price * shares.intValue();
  
// keep a running total
total += value;
}
return total;
}
  
/**
* Increments the number of stock shares in the specified portfolio.
*/
private void buyStock( DatedMap<String,Integer,Date> portfolio, String stock, int numShares, Date date )
{
// get the current number of shares owned
Integer currentShares = portfolio.get( stock, date );
  
// if none owned, add an entry to the dated map
if( currentShares == null )
{
portfolio.put( stock, Integer.valueOf( numShares ), date, END_OF_TIME );
return;
}
int totalShares = currentShares.intValue() + numShares;
  
// update the dated map
portfolio.put( stock, Integer.valueOf( totalShares ), date, END_OF_TIME );
}
  
public void run()
{
DatedMap<String,Integer,Date> portfolio = new TreeMapByKey<String,Integer,Date>();
double value = getPortfolioValue( portfolio, d[0] );
assert value == 0.0;
System.out.println( "Portfolio on " + d[0] + ": " + portfolio.toString( d[0] ));
buyStock( portfolio, "Compewter Materials", 100, d[10] );
buyStock( portfolio, "Mice With Wheels", 250, d[10] );
System.out.println( "Portfolio on " + d[15] + ": " + portfolio.toString( d[15] ));
value = getPortfolioValue( portfolio, d[15] );
System.out.println( "Portfolio value on " + d[15] + " is " + value );

// buy a third company's shares
buyStock( portfolio, "Global Software For Geeks", 10, d[50] );
  
// check the value on d[50]
System.out.println( "Portfolio on " + d[50] + ": " + portfolio.toString( d[50] ));
value = getPortfolioValue( portfolio, d[50] );
System.out.println( "Portfolio value on " + d[50] + " is " + value );
  
// buy some more stock on d[75]
buyStock( portfolio, "Mice With Wheels", 20, d[75] );
System.out.println( "Portfolio on " + d[80] + ": " + portfolio.toString( d[80] ));
value = getPortfolioValue( portfolio, d[80] );
System.out.println( "Portfolio value on " + d[80] + " is " + value );
System.out.println( "Entire portfolio: " + portfolio );
System.out.println( "Entire stock market: " + stockMarket );
}
  
public static void main(String[] args)
{
StockExample example = new StockExample();
example.run();
}
  
}

Add a comment
Know the answer?
Add Answer to:
need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class si...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a set of classes that work together to simulate the Stock Transaction System. You should...

    Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows:    -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on a stock market. The class's...

  • this is java m. please use netbeans if you can. 7. Person and Customer Classes Design...

    this is java m. please use netbeans if you can. 7. Person and Customer Classes Design a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the cus- tomer wishes to...

  • using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checkin...

    using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checking a parked car issuing a parking ticket if there is a parking violation. Here are the classes that need to collaborate: • The ParkedCar class: This class should simulate a parked car. The car has a make, model, color, license number. •The ParkingMeter class: This class should simulate a parking meter. The class has three parameters: − A 5-digit...

  • Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment =====================...

    Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment ===================== For this assignment you will create a set of classes from scratch (no provided class files for this assignment) that work together to simulate a police officer issuing a parking ticket. You should design the following classes / functionality within them: ===================== ParkedCar.java: ===================== This class should simulate a parked car. The class's responsibilities are as follows: - To store the car's make, model,...

  • I need help with this java project and please follow the instruction below. thank Class Project...

    I need help with this java project and please follow the instruction below. thank Class Project - Parking Ticket simulator Design a set of classes that work together to simulate a police officer issuing a parking ticket. Design the following classes: •           The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are as follows: – To know the car’s make, model, color, license number, and the number of minutes that the car has been parked. •          ...

  • Assignment 6 Due: Apr 12, 2019 at 11:59 PM A6 OOP 3 "PreferredCustomer Class" (need to...

    Assignment 6 Due: Apr 12, 2019 at 11:59 PM A6 OOP 3 "PreferredCustomer Class" (need to create Person, Customer classes described in the previous problem) Access A6 from pdf assignment file. Turn in the following files: a6main.java Customer.java Person.java PreferredCustomer.java program compile and run screenshots design document (including UML) A6 7. Person and Customer Classes esign a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator...

  • For this assignment, you will design tow classes that work together to simulate a car's fuel...

    For this assignment, you will design tow classes that work together to simulate a car's fuel gauge and odometer. The classes you will design are the following: 1. The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are: To know the car's current amount of fuel, in gallons. To report the car's current amount of fuel, in gallons. To be able to increment the amount of fuel by one gallon. This simulates putting fuel in the car....

  • Java 1. Develop a program to emulate a purchase transaction at a retail store. This program...

    Java 1. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual line item of merchandise that a customer is purchasing. The Transaction class will combine several LineItem objects and calculate an overall total price for the line item within the transaction. There will also be two test classes, one for the LineItem class and one for the...

  • Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance...

    Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance must be in the main class, and the requirement of printing a list of transactions for only the ids used when the program runs(Detailed in the Additional simulation requirements) is extremely important! Thank you so very much! Instructions: This homework models after a banking situation with ATM machine. You are required to create three classes, Account, Transaction, and the main class (with the main...

  • UML CLASS DIAGRAM This is a Design Exercise. You will need to make classes that could...

    UML CLASS DIAGRAM This is a Design Exercise. You will need to make classes that could be used to stage a battle as described below. You have been tasked to create a number of items that can be used in an online game. All items can be used on a game character who will have a name, a number of health-points and a bag to hold the items.   Here are examples of items that can be made: Item type of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT