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
1895fb94
You need to sign in or sign up before continuing.
Commit
1895fb94
authored
Jan 21, 2018
by
SAURABH GUPTA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding the Processing Logic
parent
ae9b2b8c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
62 deletions
+141
-62
src/Order/Main.java
src/Order/Main.java
+141
-0
src/orders/Main.java
src/orders/Main.java
+0
-62
No files found.
src/Order/Main.java
0 → 100644
View file @
1895fb94
/**
*
*/
package
Order
;
import
java.util.ArrayList
;
import
java.util.Scanner
;
import
javax.swing.plaf.synth.SynthSpinnerUI
;
/**
* @author guptas
*
*/
class
Order
{
String
ord_ID
;
String
type
;
String
product
;
String
pro_ID
;
int
price
;
int
qty
;
String
cust_ID
;
void
read
()
{
Scanner
s
=
new
Scanner
(
System
.
in
);
this
.
ord_ID
=
s
.
nextLine
();
this
.
type
=
s
.
next
();
this
.
product
=
s
.
next
();
this
.
price
=
s
.
nextInt
();
this
.
qty
=
s
.
nextInt
();
this
.
cust_ID
=
s
.
next
();
}
void
show
()
{
System
.
out
.
println
(
"OrderID :"
+
this
.
ord_ID
);
System
.
out
.
println
(
"Type :"
+
this
.
type
);
System
.
out
.
println
(
"Product :"
+
this
.
product
);
System
.
out
.
println
(
"Price :"
+
this
.
price
);
System
.
out
.
println
(
"Quantity :"
+
this
.
qty
);
System
.
out
.
println
(
"CustomerID :"
+
this
.
cust_ID
);
}
public
void
Process
(
ArrayList
<
Order
>
orders
)
{
int
lenth
=
orders
.
size
();
if
(
"Sell"
.
equalsIgnoreCase
(
this
.
type
))
{
int
i
=
0
;
while
(
lenth
--
>
0
)
{
Order
o
=
orders
.
get
(
i
++);
if
(
(
"Buy"
.
equalsIgnoreCase
(
o
.
type
))
&&
(
o
.
product
.
equalsIgnoreCase
(
this
.
product
))
&&
(
o
.
price
>=
this
.
price
))
{
if
(
o
.
qty
>
this
.
qty
)
{
o
.
qty
-=
this
.
qty
;
// orders.add(i-1, o);
System
.
out
.
println
(
"break"
);
break
;
}
else
{
this
.
qty
-=
o
.
qty
;
// orders.add(lenth, this);
System
.
out
.
println
(
"continue"
);
continue
;
}
}
}
}
else
if
(
this
.
type
==
"Buy"
||
this
.
type
==
"buy"
)
{
int
i
=
0
;
while
(
lenth
--
>
0
)
{
Order
o
=
orders
.
get
(
i
++);
if
(
(
o
.
type
==
"Sell"
||
o
.
type
==
"sell"
)
&&
(
o
.
product
.
equals
(
this
.
product
))
&&
(
o
.
price
<=
this
.
price
))
{
if
(
o
.
qty
>
this
.
qty
)
{
o
.
qty
-=
this
.
qty
;
// orders.add(i-1, o);
System
.
out
.
println
(
"break"
);
break
;
}
else
{
this
.
qty
-=
o
.
qty
;
// orders.add(lenth, this);
System
.
out
.
println
(
"continue"
);
continue
;
}
}
}
}
}
public
void
pending
(
ArrayList
<
Order
>
orders
)
{
// TODO Auto-generated method stub
int
lenth
=
orders
.
size
();
System
.
out
.
println
(
"Number of orders left : "
+
lenth
);
int
i
=
0
;
while
(
lenth
--
>
0
)
{
System
.
out
.
println
(
"\nORDER #"
+(
i
+
1
));
Order
o
=
orders
.
get
(
i
++);
o
.
show
();
}
}
}
public
class
Main
{
/**
* @param args
*/
public
static
void
main
(
String
[]
args
)
{
// TODO Auto-generated method stub
char
choice
=
'n'
;
int
i
=
0
;
ArrayList
<
Order
>
orders
=
new
ArrayList
<
Order
>();
do
{
Order
O1
=
new
Order
();
System
.
out
.
println
(
"Provide Order Details : \n [orderID : Type : Product : Price : Quantity : CustID]\n"
);
O1
.
read
();
///Reading new orders
orders
.
add
(
O1
);
//Added in the list
O1
.
Process
(
orders
);
// Finding the match
System
.
out
.
println
(
"\nPending Orders till now are : "
);
O1
.
pending
(
orders
);
//Pending orders.
System
.
out
.
println
(
"\nWant to add new order : [y/n] \n "
);
@SuppressWarnings
(
"resource"
)
Scanner
s
=
new
Scanner
(
System
.
in
);
choice
=
s
.
next
().
charAt
(
0
);
}
while
(
choice
==
'y'
);
}
}
src/orders/Main.java
deleted
100644 → 0
View file @
ae9b2b8c
/**
*
*/
package
orders
;
import
java.util.Scanner
;
import
javax.swing.plaf.synth.SynthSpinnerUI
;
/**
* @author guptas
*
*/
class
Orders
{
String
ord_ID
;
String
type
;
String
product
;
String
pro_ID
;
int
price
;
int
qty
;
String
cust_ID
;
public
void
read
()
{
Scanner
s
=
new
Scanner
(
System
.
in
);
this
.
ord_ID
=
s
.
next
();
this
.
type
=
s
.
next
();
this
.
product
=
s
.
next
();
this
.
pro_ID
=
s
.
next
();
this
.
price
=
s
.
nextInt
();
this
.
qty
=
s
.
nextInt
();
this
.
cust_ID
=
s
.
next
();
}
public
void
show
()
{
System
.
out
.
println
(
"OrderID :"
+
this
.
ord_ID
+
"\n"
);
System
.
out
.
println
(
"Type :"
+
this
.
type
+
"\n"
);
System
.
out
.
println
(
"Product :"
+
this
.
product
+
"\n"
);
System
.
out
.
println
(
"ProductID :"
+
this
.
pro_ID
+
"\n"
);
System
.
out
.
println
(
"Price :"
+
this
.
price
+
"\n"
);
System
.
out
.
println
(
"Quantity :"
+
this
.
qty
+
"\n"
);
System
.
out
.
println
(
"CustomerID :"
+
this
.
cust_ID
+
"\n"
);
}
}
public
class
Main
{
/**
* @param args
*/
public
static
void
main
(
String
[]
args
)
{
// TODO Auto-generated method stub
Orders
O1
=
new
Orders
();
System
.
out
.
println
(
"Provide Order Details : \n [orderID : Type : Product : ProductID : Price : Quantity : CustID]\n"
);
O1
.
read
();
System
.
out
.
println
(
"These are details of your order: \n"
);
O1
.
show
();
}
}
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