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
5e3b5e17
Commit
5e3b5e17
authored
Jan 22, 2018
by
SAURABH GUPTA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Matched Order and Junit Test for Process Method in orderProcessing
CLass
parent
4e5b4baf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
13 deletions
+80
-13
src/Order/Order.java
src/Order/Order.java
+25
-0
src/Order/OrderProcessing.java
src/Order/OrderProcessing.java
+30
-11
src/Order/ProcessTest.java
src/Order/ProcessTest.java
+20
-0
src/main/Main.java
src/main/Main.java
+5
-2
No files found.
src/Order/Order.java
View file @
5e3b5e17
...
...
@@ -14,6 +14,30 @@ import javax.swing.plaf.synth.SynthSpinnerUI;
*
*/
public
class
Order
{
public
Order
()
{
}
public
Order
(
Order
O
)
{
super
();
this
.
ord_ID
=
O
.
ord_ID
;
this
.
type
=
O
.
type
;
this
.
product
=
O
.
product
;
this
.
price
=
O
.
price
;
this
.
qty
=
O
.
qty
;
this
.
cust_ID
=
O
.
cust_ID
;
}
public
Order
(
String
ord_ID
,
String
type
,
String
product
,
int
price
,
int
qty
,
String
cust_ID
)
{
super
();
this
.
ord_ID
=
ord_ID
;
this
.
type
=
type
;
this
.
product
=
product
;
this
.
price
=
price
;
this
.
qty
=
qty
;
this
.
cust_ID
=
cust_ID
;
}
String
ord_ID
;
String
type
;
...
...
@@ -22,6 +46,7 @@ public class Order {
int
price
;
int
qty
;
String
cust_ID
;
public
void
read
()
{
Scanner
s
=
new
Scanner
(
System
.
in
);
...
...
src/Order/OrderProcessing.java
View file @
5e3b5e17
...
...
@@ -5,39 +5,47 @@ import java.util.ArrayList;
public
class
OrderProcessing
{
private
ArrayList
<
Order
>
orderQueue
=
new
ArrayList
<
Order
>();
public
void
Process
(
Order
order
)
{
public
ArrayList
<
Order
>
Process
(
Order
order
)
{
int
lenth
=
orderQueue
.
size
();
ArrayList
<
Order
>
matched
=
new
ArrayList
<
Order
>();
if
(
"Sell"
.
equalsIgnoreCase
(
order
.
type
))
{
int
i
=
0
;
while
(
lenth
--
>
0
)
{
Order
o
=
orderQueue
.
get
(
i
++);
if
((
"Buy"
.
equalsIgnoreCase
(
o
.
type
))
&&
(
o
.
product
.
equalsIgnoreCase
(
order
.
product
))
&&
(
o
.
price
>=
order
.
price
))
{
if
(
o
.
qty
>
order
.
qty
)
{
Order
o1
=
new
Order
(
o
);
matched
.
add
(
o1
);
if
(
o
.
qty
>=
order
.
qty
)
{
o
.
qty
-=
order
.
qty
;
o1
.
qty
=
order
.
qty
;
order
.
qty
=
0
;
break
;
}
else
{
order
.
qty
-=
o
.
qty
;
o
.
qty
=
0
;
o1
.
qty
=
0
;
continue
;
}
}
}
}
else
{
System
.
out
.
println
(
"HERE"
);
int
i
=
0
;
while
(
lenth
--
>
0
)
{
Order
o
=
orderQueue
.
get
(
i
++);
if
(
"Sell"
.
equalsIgnoreCase
(
o
.
type
)
&&
(
o
.
product
.
equalsIgnoreCase
(
order
.
product
))
&&
(
o
.
price
<=
order
.
price
))
{
Order
o1
=
new
Order
(
o
);
matched
.
add
(
o1
);
if
(
o
.
qty
>=
order
.
qty
)
{
o
.
qty
-=
order
.
qty
;
o1
.
qty
=
order
.
qty
;
order
.
qty
=
0
;
break
;
}
else
{
order
.
qty
-=
o
.
qty
;
o
.
qty
=
0
;
o1
.
qty
=
0
;
continue
;
}
}
...
...
@@ -45,22 +53,33 @@ public class OrderProcessing {
}
orderQueue
.
add
(
order
);
System
.
out
.
println
(
orderQueue
);
return
matched
;
}
public
ArrayList
<
Order
>
getOrderQueue
()
{
return
orderQueue
;
}
public
void
pending
()
{
public
void
pending
(
ArrayList
<
Order
>
matched
)
{
// TODO Auto-generated method stub
int
lenth
=
orderQueue
.
size
();
System
.
out
.
println
(
"Number of orders left : "
+
lenth
);
int
i
=
0
;
while
(
lenth
--
>
0
)
for
(
int
i
=
0
;
i
<
orderQueue
.
size
();)
{
System
.
out
.
println
(
"\nORDER #"
+(
i
+
1
));
Order
order
=
orderQueue
.
get
(
i
++);
if
(
order
.
qty
!=
0
)
order
.
show
();
Order
order
=
orderQueue
.
get
(
i
);
if
(
order
.
qty
!=
0
)
{
System
.
out
.
println
(
"Order #"
+
i
++);
order
.
show
();
}
else
{
orderQueue
.
remove
(
order
);
}
}
}
public
void
matched
(
ArrayList
<
Order
>
matched
)
{
// TODO Auto-generated method stub
for
(
int
i
=
0
;
i
<
matched
.
size
();
i
++)
matched
.
get
(
i
).
show
();
}
}
src/Order/ProcessTest.java
0 → 100644
View file @
5e3b5e17
package
Order
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
java.util.ArrayList
;
import
org.junit.jupiter.api.Test
;
class
ProcessTest
{
@Test
void
testProcess
()
{
OrderProcessing
junit
=
new
OrderProcessing
();
assertEquals
((
junit
.
Process
(
new
Order
(
"t1"
,
"sell"
,
"apple"
,
325
,
25
,
"c01"
))).
size
(),
0
);
assertEquals
((
junit
.
Process
(
new
Order
(
"t2"
,
"sell"
,
"apple"
,
320
,
30
,
"c02"
))).
size
(),
0
);
assertEquals
((
junit
.
Process
(
new
Order
(
"t3"
,
"buy"
,
"apple"
,
315
,
20
,
"c03"
))).
size
(),
0
);
assertEquals
((
junit
.
Process
(
new
Order
(
"t4"
,
"buy"
,
"apple"
,
330
,
35
,
"c04"
))).
size
(),
2
);
}
}
src/main/Main.java
View file @
5e3b5e17
...
...
@@ -22,10 +22,13 @@ public class Main {
"Provide Order Details : \n [orderID : Type : Product : Price : Quantity : CustID]\n"
);
O1
.
read
();
///Reading new orders
// orders.add(O1); //Added in the list
orderProcessing
.
Process
(
O1
);
// Finding the match
ArrayList
<
Order
>
matched
=
orderProcessing
.
Process
(
O1
);
// Finding the match
System
.
out
.
println
(
"Matched Orders are : "
);
orderProcessing
.
matched
(
matched
);
System
.
out
.
println
(
"\nPending Orders till now are : "
);
orderProcessing
.
pending
();
//Pending orders.
orderProcessing
.
pending
(
matched
);
//Pending orders.
System
.
out
.
println
(
"\nWant to add new order : [y/n] \n "
);
@SuppressWarnings
(
"resource"
)
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