Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS682-HW1-OrderMatching
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Rohit Prasad
CS682-HW1-OrderMatching
Commits
bd7df177
Commit
bd7df177
authored
Jan 22, 2018
by
Rohit Prasad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Execution code for the program
parent
b5779b55
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
src/Main.java
src/Main.java
+53
-0
No files found.
src/Main.java
0 → 100644
View file @
bd7df177
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
int
time
=
0
;
OrderMatching
orderMatching
=
new
OrderMatching
();
do
{
System
.
out
.
println
(
"Provide input in this format:"
);
System
.
out
.
println
(
"type,from,stock,qnt,price"
);
String
line
=
br
.
readLine
();
String
[]
inputs
=
line
.
split
(
","
);
Customer
c
=
new
Customer
(
inputs
[
1
]);
Stock
stock
=
new
Stock
(
inputs
[
2
]);
Order
order
;
if
(
"sell"
.
compareToIgnoreCase
(
inputs
[
0
])
==
0
)
{
order
=
new
SellOrder
(
time
++,
c
,
stock
,
Integer
.
parseInt
(
inputs
[
3
]),
Integer
.
parseInt
(
inputs
[
4
]));
}
else
{
order
=
new
BuyOrder
(
time
++,
c
,
stock
,
Integer
.
parseInt
(
inputs
[
3
]),
Integer
.
parseInt
(
inputs
[
4
]));
}
// check if order is valid
if
(!
orderMatching
.
validate
(
order
))
{
System
.
out
.
println
(
"Invalid order provided!"
);
}
ArrayList
<
Order
>
matchedOrders
=
orderMatching
.
findMatchedOrders
(
order
);
if
(!
matchedOrders
.
isEmpty
())
{
System
.
out
.
print
(
"Following trades happened for "
+
order
.
getType
()
+
" order: "
);
System
.
out
.
println
(
order
);
int
count
=
1
;
for
(
Order
o
:
matchedOrders
)
{
System
.
out
.
print
(
count
++
+
": "
);
System
.
out
.
println
(
o
);
}
}
System
.
out
.
println
();
}
while
(
true
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment