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
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SAURABH GUPTA
CS682-HW1-OrderMatching
Commits
1deea996
Commit
1deea996
authored
Jan 22, 2018
by
SAURABH GUPTA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fully Tested and Commented Code
parent
5e3b5e17
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
17 deletions
+46
-17
src/Order/Order.java
src/Order/Order.java
+14
-9
src/Order/OrderProcessing.java
src/Order/OrderProcessing.java
+19
-3
src/main/Main.java
src/main/Main.java
+13
-5
No files found.
src/Order/Order.java
View file @
1deea996
...
@@ -14,11 +14,23 @@ import javax.swing.plaf.synth.SynthSpinnerUI;
...
@@ -14,11 +14,23 @@ import javax.swing.plaf.synth.SynthSpinnerUI;
*
*
*/
*/
public
class
Order
{
public
class
Order
{
String
ord_ID
;
String
type
;
String
product
;
String
pro_ID
;
int
price
;
int
qty
;
String
cust_ID
;
//Empty Constructor
public
Order
()
public
Order
()
{
{
}
}
//Copy Constructor
public
Order
(
Order
O
)
public
Order
(
Order
O
)
{
{
super
();
super
();
...
@@ -29,6 +41,8 @@ public class Order {
...
@@ -29,6 +41,8 @@ public class Order {
this
.
qty
=
O
.
qty
;
this
.
qty
=
O
.
qty
;
this
.
cust_ID
=
O
.
cust_ID
;
this
.
cust_ID
=
O
.
cust_ID
;
}
}
//Constructor for Initialization
public
Order
(
String
ord_ID
,
String
type
,
String
product
,
int
price
,
int
qty
,
String
cust_ID
)
{
public
Order
(
String
ord_ID
,
String
type
,
String
product
,
int
price
,
int
qty
,
String
cust_ID
)
{
super
();
super
();
this
.
ord_ID
=
ord_ID
;
this
.
ord_ID
=
ord_ID
;
...
@@ -39,15 +53,6 @@ public class Order {
...
@@ -39,15 +53,6 @@ public class Order {
this
.
cust_ID
=
cust_ID
;
this
.
cust_ID
=
cust_ID
;
}
}
String
ord_ID
;
String
type
;
String
product
;
String
pro_ID
;
int
price
;
int
qty
;
String
cust_ID
;
public
void
read
()
{
public
void
read
()
{
Scanner
s
=
new
Scanner
(
System
.
in
);
Scanner
s
=
new
Scanner
(
System
.
in
);
this
.
ord_ID
=
s
.
nextLine
();
this
.
ord_ID
=
s
.
nextLine
();
...
...
src/Order/OrderProcessing.java
View file @
1deea996
...
@@ -2,12 +2,20 @@ package Order;
...
@@ -2,12 +2,20 @@ package Order;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
//Class for Processing the Orders
public
class
OrderProcessing
{
public
class
OrderProcessing
{
//OrderQueue in which all Orders are added and removed if they got a match.
private
ArrayList
<
Order
>
orderQueue
=
new
ArrayList
<
Order
>();
private
ArrayList
<
Order
>
orderQueue
=
new
ArrayList
<
Order
>();
//Processing Logic
public
ArrayList
<
Order
>
Process
(
Order
order
)
{
public
ArrayList
<
Order
>
Process
(
Order
order
)
{
int
lenth
=
orderQueue
.
size
();
int
lenth
=
orderQueue
.
size
();
//Matched Queue for storing the matched orders at that time only i.e. why i have declared locally so that it will persist for more than one orders.
ArrayList
<
Order
>
matched
=
new
ArrayList
<
Order
>();
ArrayList
<
Order
>
matched
=
new
ArrayList
<
Order
>();
//if current order is sell type order
if
(
"Sell"
.
equalsIgnoreCase
(
order
.
type
))
{
if
(
"Sell"
.
equalsIgnoreCase
(
order
.
type
))
{
int
i
=
0
;
int
i
=
0
;
while
(
lenth
--
>
0
)
{
while
(
lenth
--
>
0
)
{
...
@@ -29,7 +37,9 @@ public class OrderProcessing {
...
@@ -29,7 +37,9 @@ public class OrderProcessing {
}
}
}
}
}
}
}
else
{
}
//if current order is buy type order
else
{
int
i
=
0
;
int
i
=
0
;
while
(
lenth
--
>
0
)
{
while
(
lenth
--
>
0
)
{
Order
o
=
orderQueue
.
get
(
i
++);
Order
o
=
orderQueue
.
get
(
i
++);
...
@@ -56,27 +66,33 @@ public class OrderProcessing {
...
@@ -56,27 +66,33 @@ public class OrderProcessing {
return
matched
;
return
matched
;
}
}
//getting the Current OrderQueue
public
ArrayList
<
Order
>
getOrderQueue
()
{
public
ArrayList
<
Order
>
getOrderQueue
()
{
return
orderQueue
;
return
orderQueue
;
}
}
public
void
pending
(
ArrayList
<
Order
>
matched
)
{
//Function for pending orders
public
void
pending
()
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
for
(
int
i
=
0
;
i
<
orderQueue
.
size
();)
for
(
int
i
=
0
;
i
<
orderQueue
.
size
();)
{
{
Order
order
=
orderQueue
.
get
(
i
);
Order
order
=
orderQueue
.
get
(
i
);
if
(
order
.
qty
!=
0
)
if
(
order
.
qty
!=
0
)
{
{
//prints only non-zero quantity orders
System
.
out
.
println
(
"Order #"
+
i
++);
System
.
out
.
println
(
"Order #"
+
i
++);
order
.
show
();
order
.
show
();
}
}
else
else
{
{
//remove the zero quantity orders
orderQueue
.
remove
(
order
);
orderQueue
.
remove
(
order
);
}
}
}
}
}
}
//Function for returning matched orders
public
void
matched
(
ArrayList
<
Order
>
matched
)
{
public
void
matched
(
ArrayList
<
Order
>
matched
)
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
for
(
int
i
=
0
;
i
<
matched
.
size
();
i
++)
for
(
int
i
=
0
;
i
<
matched
.
size
();
i
++)
...
...
src/main/Main.java
View file @
1deea996
...
@@ -10,7 +10,7 @@ public class Main {
...
@@ -10,7 +10,7 @@ public class Main {
/**
/**
* @param args
* @param args
*/
*/
//Main Function
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
char
choice
=
'n'
;
char
choice
=
'n'
;
...
@@ -18,17 +18,25 @@ public class Main {
...
@@ -18,17 +18,25 @@ public class Main {
OrderProcessing
orderProcessing
=
new
OrderProcessing
();
OrderProcessing
orderProcessing
=
new
OrderProcessing
();
do
{
do
{
Order
O1
=
new
Order
();
Order
O1
=
new
Order
();
//Reading new order
System
.
out
.
println
(
System
.
out
.
println
(
"Provide Order Details : \n [orderID : Type : Product : Price : Quantity : CustID]\n"
);
"Provide Order Details : \n [orderID : Type : Product : Price : Quantity : CustID]\n"
);
O1
.
read
();
///Reading new orders
O1
.
read
();
// orders.add(O1); //Added in the list
ArrayList
<
Order
>
matched
=
orderProcessing
.
Process
(
O1
);
// Finding the match
// Finding the match
ArrayList
<
Order
>
matched
=
orderProcessing
.
Process
(
O1
);
// Producing the Matched Orders
System
.
out
.
println
(
"Matched Orders are : "
);
System
.
out
.
println
(
"Matched Orders are : "
);
orderProcessing
.
matched
(
matched
);
orderProcessing
.
matched
(
matched
);
//Producing the Pending Orders
System
.
out
.
println
(
"\nPending Orders till now are : "
);
System
.
out
.
println
(
"\nPending Orders till now are : "
);
orderProcessing
.
pending
();
orderProcessing
.
pending
(
matched
);
//Pending orders.
//Asking for New Orders
System
.
out
.
println
(
"\nWant to add new order : [y/n] \n "
);
System
.
out
.
println
(
"\nWant to add new order : [y/n] \n "
);
@SuppressWarnings
(
"resource"
)
@SuppressWarnings
(
"resource"
)
Scanner
s
=
new
Scanner
(
System
.
in
);
Scanner
s
=
new
Scanner
(
System
.
in
);
...
...
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