


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();
}
}
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...
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 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 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 ===================== 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 - 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. • ...
C# Car Instrument Simulation (Updated Question) Car Instrument Simulator Design a set of classes that work together to simulate a car’s fuel gauge and odometer. The classes you will design are the following: • The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are as follows: o To know the car’s current amount of fuel, in liters. o To report the car’s current amount of fuel, in liters. o To be able to increment the amount of...
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...
Please use Java Question 3: Person and Customer classes: Design a class named Person with properties for holding a person's name, address, and telephone number. Next, design a class named Customer, which is derived from the Person class. The Customer class should have a property for a customer number and a Boolean property indicating whether wishes to be on a mailing list. Demonstrate an object of customer class in a simple GUI application. Write the code include appropriate input validation,...
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 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...