|
Problem: A stock order is an order to buy/sell a given quantity of stocks of
specified company. Person willing to buy or sell a stock will submit an order to a
stock exchange, where it is executed against the opposite side order of same
company i.e, buy order is executed against an existing sell order and vice-versa.
The criteria for stock orders execution is that, they should belong to same company,
they are opposite sides ( Buy vs Sell), and order of arrival i.e, the order is executed
against the first available order. The left over quantity after execution is called
remaining quantity. For example, if a buy order of quantity 10 is executed against a
sell order of quantity 5, the remaining quantity of buy and sell orders are 5 and 0
respectively. An order status is called OPEN if the remaining quantity is greater
than zero(>0), otherwise it’s called CLOSED(i.e., remaining quantity = 0). Your
task is to implement stock order execution system which takes input orders from
console, process them and gives status and remaining quantity of all the orders as
output. The solution should efficiently handle high volumes of orders [ brute-force
approach may not be a scalable solution].
|
|
|
|
|
We don't do people's homework for them. Just try it yourself.
|
|
|
|
|
Member 11816884 wrote: Your task is to That means you, not someone else. People here are willing to help with problems you encounter in code that you have written. But no one is going to do your work for you.
|
|
|
|
|
Besides it looks more like a problem that needs analyzing than a programming problem.
If you translate it into real English (vs computer science teacher's English) it will be 1000 times easier for you to understand.
|
|
|
|
|
Hi everyone. I have sort of an unusual question. I'm a tech recruiter but I just became a recruiter this week. I don't know how to code at least not now, but took an AP college level class in java during my senior year in high school in 2003. On my resume for the job, i had mebtuoned that i took a class in java a while ago and he appeared in impressrd in the interview that i had some sort of experience with java. There is actually a couple of other recruiters in the office who also took java classes at some point. My boss does not know how to code and recently sent an email to the three of us asking if could have a copy of one of our notes from a java class we took.
I think he was under the impression that the class was taken more recently. He said preferably one that had been taken in the last three years I can give them to him, but would they be less helpful if they are from 12 years ago? I'd love to have him think, without lying to him, obviously, that I had taken the class more around 2012 or so. I think he knows it wasnt the last two years.
I just started and thought I wasn't picking things up fast enough so would love him to think well of me about this. I'm also going to take a mooc class on java to freshen my knowledge.
|
|
|
|
|
|
There's millions of tutorials on internet, actually a good manual or good book if you want read quickly is te better choice.
|
|
|
|
|
Message Closed
modified 7-Feb-18 13:12pm.
|
|
|
|
|
Please do not use the forums for soliciting reviews. If your blog is worth reading then those who are interested will see it and comment as appropriate.
|
|
|
|
|
ok, so it is done i.e. I have already posted this, what do I do now? can I delete this post?
i will obviously avoid posting this in the future.
"Please do not use the forums for soliciting reviews."
ok poor choice of words on my part.
"If your blog is worth reading"
mate, I get a monthly pageview count for my blog. Looking at the count, I already know that my blog is worth reading. Being a smart Java developer, I was stuck on a number of rather simple problems when I started making my iOS app, it was almost demoralising, hence the primary reason for the blog or my Github project template, is for other Java devs to not be stuck on the same problems I was stuck on.
|
|
|
|
|
A program that take two parameters n and i. The program should generate all possible sums that lead to n being made up of i variable.
|
|
|
|
|
If you are expecting someone to write this code for you, then I am afraid you have come to the wrong place. You should first write the required mathematical algorithm in plain language, and then convert that to code. When you have a specific question then come back here and people will try to help you.
|
|
|
|
|
Please how can i input jquery slideshows in my web?
|
|
|
|
|
This is the Java forum; try the Javascript forum for jQuery issues.
|
|
|
|
|
please how can i start using java for programming (not just in command prompt)?
|
|
|
|
|
|
thanks alot
|
|
|
|
|
|
class NewThread implements Runnable {
String name;
Thread t;
NewThread(String threadname) {
name = threadname;
t = new Thread(this, name);
System.out.println("New thread: " + t);
t.start();
}
public void run() {
try {
for (int i = 5; i > 0; i--) {
System.out.println(name + ": " + i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.out.println(name + " interrupted.");
}
System.out.println(name + " exiting.");
}
}
public class Main {
public static void main(String args[]) {
NewThread ob1 = new NewThread("One");
NewThread ob2 = new NewThread("Two");
NewThread ob3 = new NewThread("Three");
System.out.println("Thread One is alive: " + ob1.t.isAlive());
System.out.println("Thread Two is alive: " + ob2.t.isAlive());
System.out.println("Thread Three is alive: " + ob3.t.isAlive());
try {
System.out.println("Waiting for threads to finish.");
ob1.t.join();
ob2.t.join();
ob3.t.join();
} catch (InterruptedException e) {
System.out.println("Main thread Interrupted");
}
System.out.println("Thread One is alive: " + ob1.t.isAlive());
System.out.println("Thread Two is alive: " + ob2.t.isAlive());
System.out.println("Thread Three is alive: " + ob3.t.isAlive());
System.out.println("Main thread exiting.");
}
}
Joining the default main thread with a background thread
public class Main {
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
System.out.println("sleeping for 5 seconds.");
try {
Thread.sleep(5000);
} catch (Exception ie) {
}
System.out.println("Worker thread is done");
}
};
Thread thd = new Thread(r);
thd.start();
System.out.println("main thread is running.");
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
}
System.out.println("main thread is waiting for worker thread.");
try {
thd.join();
} catch (InterruptedException ie) {
}
}
}
in these wt is meaning of ob1.t.join()
like statement plz anyone
|
|
|
|
|
It creates a delay until the thread completes. You should always check the documentation[^] first.
|
|
|
|
|
How JVM deals with machine to execute a java program and what's about its register organization and memory management in reference of real machine ?
|
|
|
|
|
|
OK...I am new to programming and I am trying to use existing code for a project. Every time I try to run it, it comes abck saying there is "no main class" what am I doing worng and what should I do to fix it? Please help me and do it with "semi-retarded jargon" I will not benefit from your help if the responses are too technical.
Please see below:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.NumberFormat;
import java.util.Scanner;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
class Donor
{
private String donorName;
private String nameOfCharity;
private double amountPledged;
public Donor(String donorName, String nameOfCharity, double amountPledged) {
this.donorName = donorName;
this.nameOfCharity = nameOfCharity;
this.amountPledged = amountPledged;
}
public String getDonorName() {
return donorName;
}
public void setDonorName(String donorName) {
this.donorName = donorName;
}
public String getNameOfCharity() {
return nameOfCharity;
}
public void setNameOfCharity(String nameOfCharity) {
this.nameOfCharity = nameOfCharity;
}
public double getAmountPledged() {
return amountPledged;
}
public void setAmountPledged(double amountPledged) {
this.amountPledged = amountPledged;
}
}
public class Charity extends JFrame implements ActionListener
{
private JLabel donorNameLabel;
private JLabel nameOfCharityLabel;
private JLabel amountPledgedLabel;
private JTextField donorNameField;
private JTextField nameOfCharityField;
private JFormattedTextField amountPledgedField;
private JButton addButton;
private JButton viewCharities;
private JButton addNewCharity;
private JPanel firstPanel;
private JPanel secondPanel;
private NumberFormat amountNumberFormat;
private JTable charitiesTable;
private JTableHeader tableHeader;
private DefaultTableModel defaultTableModel;
private InputStream fileInputStream;
private DataInputStream dataInputStream;
private Scanner fileInput;
@SuppressWarnings("LeakingThisInConstructor")
public Charity()
{
setSize(650, 700);
setLayout(new BorderLayout());
setTitle("Charity");
setDefaultCloseOperation(EXIT_ON_CLOSE);
donorNameLabel = new JLabel("Enter Donor Name");
nameOfCharityLabel = new JLabel("Enter Charity Name");
amountPledgedLabel = new JLabel("Enter Amount Pledged");
donorNameField = new JTextField(25);
nameOfCharityField = new JTextField(25);
amountNumberFormat = NumberFormat.getInstance();
amountPledgedField = new JFormattedTextField(amountNumberFormat);
amountPledgedField.setColumns(25);
firstPanel = new JPanel(new GridLayout(6,1,0,10));
firstPanel.add(donorNameLabel);
firstPanel.add(donorNameField);
firstPanel.add(nameOfCharityLabel);
firstPanel.add(nameOfCharityField);
firstPanel.add(amountPledgedLabel);
firstPanel.add(amountPledgedField);
addButton = new JButton("Add Charity");
addButton.addActionListener(this);
addNewCharity = new JButton("Add New Charity");
addNewCharity.addActionListener(this);
viewCharities = new JButton("View Charity List");
viewCharities.addActionListener(this);
secondPanel = new JPanel();
secondPanel.add(addButton);
secondPanel.add(addNewCharity);
secondPanel.add(viewCharities);
defaultTableModel = new DefaultTableModel();
defaultTableModel.addColumn(new String("Donor Name"));
defaultTableModel.addColumn(new String("Charity Name"));
defaultTableModel.addColumn(new String("Amount Pledged"));
charitiesTable = new JTable(defaultTableModel);
charitiesTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
tableHeader = charitiesTable.getTableHeader();
tableHeader.setBackground(Color.yellow);
JScrollPane scrollPane = new JScrollPane(charitiesTable);
secondPanel.add(scrollPane);
add(firstPanel,BorderLayout.NORTH);
add(secondPanel,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent event)
{
Object eventSource = event.getSource();
String donorName;
String charityName;
String amountPledgedText;
double amountPledged;
Donor donor;
boolean isValidInput = true;
if(eventSource == addButton)
{
donorName = donorNameField.getText().trim();
charityName = nameOfCharityField.getText().trim();
amountPledgedText = amountPledgedField.getText().trim();
if(donorName.equals(""))
{
JOptionPane.showMessageDialog(this, "Please enter donor's name.", "Error", JOptionPane.ERROR_MESSAGE);
isValidInput = false;
}
if(charityName.equals(""))
{
JOptionPane.showMessageDialog(this, "Please enter charity name.", "Error", JOptionPane.ERROR_MESSAGE);
isValidInput = false;
}
if(amountPledgedText.equals(""))
{
JOptionPane.showMessageDialog(this, "Please enter amount pledged.", "Error", JOptionPane.ERROR_MESSAGE);
isValidInput = false;
}
if(isValidInput)
{
amountPledged = ((Number)(amountPledgedField.getValue())).doubleValue();
if(amountPledged<0.0)
{
JOptionPane.showMessageDialog(this, "Please enter a valid amount.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
donor = new Donor(donorName, charityName, amountPledged);
writeToFile(donor);
JOptionPane.showMessageDialog(this, "Charity has been successfully added.", "Charity Added", JOptionPane.INFORMATION_MESSAGE);
}
}
else if(eventSource == addNewCharity)
{
donorNameField.setText("");
nameOfCharityField.setText("");
amountPledgedField.setText("");
}
else if(eventSource == viewCharities)
{
clearTable();
Vector<Donor> donorList = readFile();
int numberOfCharities = donorList.size();
for(int i=0;i<numberOfCharities;i++)
{
donor = (Donor)donorList.elementAt(i);
defaultTableModel.insertRow(charitiesTable.getRowCount(), new Object[]{donor.getDonorName(),donor.getNameOfCharity(),"$"+donor.getAmountPledged()});
}
}
}
private void clearTable()
{
int numberOfRows = charitiesTable.getRowCount();
while(numberOfRows>0)
{
defaultTableModel.removeRow(0);
numberOfRows--;
}
}
private boolean writeToFile(Donor donor)
{
FileWriter fstream;
try {
String filePath = "Charity List.txt";
fstream = new FileWriter(filePath,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(donor.getDonorName());
out.write("\r\n");
out.write(donor.getNameOfCharity());
out.write("\r\n");
out.write(""+donor.getAmountPledged());
out.write("\r\n");
out.close();
return true;
}
catch (IOException e1)
{
e1.printStackTrace();
return false;
}
}
private Vector<Donor> readFile()
{
String charityDetails = "";
String nameOfDonor = "";
String nameOfCharity = "";
String amount = "";
Vector<Donor> donorList = new Vector<Donor>();
try
{
fileInputStream = new FileInputStream("Charity List.txt");
}
catch (FileNotFoundException e)
{
JOptionPane.showMessageDialog(this, "Charity List not found.");
return null;
}
dataInputStream = new DataInputStream(fileInputStream);
fileInput = new Scanner(new InputStreamReader(dataInputStream));
try
{
if(fileInputStream==null)
{
JOptionPane.showMessageDialog(this, "Charity List not found.");
return null;
}
while(fileInput.hasNext())
{
if(fileInput.hasNext())
{
nameOfDonor = fileInput.nextLine();
}
if(fileInput.hasNext())
{
nameOfCharity = fileInput.nextLine();
}
if(fileInput.hasNext())
{
amount = fileInput.nextLine();
}
Donor donor = new Donor(nameOfDonor, nameOfCharity, Double.parseDouble(amount));
donorList.addElement(donor);
}
dataInputStream.close();
}
catch(FileNotFoundException e)
{
System.out.println("File not found.");
return null;
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
return donorList;
}
public static void main(String[] args)
{
Charity charity = new Charity();
charity.setVisible(true);
}
}
|
|
|
|
|
|
public your class
|
|
|
|