CS210 (221) Data StructuresPackage Delivery tool
Several businesses offer delivery of their products and services. Nowadays, many people depend on having
items delivered to their homes or workplaces. This trend has opened new job opportunities and raised the need
to increase the delivery manpower. In order to motivate people to join this workforce, delivery men usually
earn a financial payement for every package they deliver. Somethmes, this payment may depend on the
package weight, size or destination.
Your 2-student team is employed to build a calculation tool to facilitate the estimation of the payment
Assuming that you are working on the back-end of this application, you will write a java software to store
employees’ data and process various requests. Your tool reads data as sets of commands from console, in
batches, processes this data and computes the earning and provides necessary output on console. This tool
would use a singly linked list to implement the various attributes, methods and classes written in the java
programming language.
Your project implements three classes namely Node, SList and Solution.
The following provides an API for your project classes.
Node
int packageID;
int eID;
int expectedDate;
int nItems;
String eName;
Node next;
Description
// A unique package id;
// Name of the Employee
// Expected Delivery date DDMMYYYY;
// Number of items in the package
// Employee ID number;
// Node next
Node()
Node(,,,)
// default constructor
// override constructor as necessary. You can edit the params as needed.
// returns a String with the contents of the Node as follows:
packageID eID eName expectedDate nItems
String toString();
1
Class SList implements a Sinlgy Linked List consisting of Nodes from the Node class.
SList
Node Head;
Node Tail;
int size;
Description
// Anchors the Head of the List
// Anchors the Tail of the List
// Maintains the size of the List
List();
// default constructor, you may have overloaded constructors
insert(Node N)
// inserts the node N in the correct position, ordered by the expectedDate.
e.g. date1 is 14022021; date2 is 01032021. date1 appears before date2. If
dates are identical, e.g. date 1 is 14022021 and date2 is 14022021, then the
node with date2 will be inserted before the node with date1.
Assume all months have exactly 30 days. There are 12 months in a year.
If a new node has a packageID which already exists, the new node should not
be added to the list.
void remove(int eID)
//removes the first occurrence (starting from head) of a node with matching
eID.
int earningAll(eID)
//This method searches for all Nodes with eID and computes the amount of
money that the employee with eID will receive for delivering ALL the
packages. The return value is rounded off (int rounding)
int earningPerMonth(eID,
month)
//This method searches for all Nodes with eID and computes the amount of
money that the employee with eID will receive for delivering the packages of
the specified month. The return value is rounded off (int rounding)
void print1(eID)
void print2(packageID)
void print3(expectedDate)
//searches for eID in the list. Prints ALL nodes with eID.
//searches for packageID in the list. Prints ONE node with packageID.
//searches for expectedDate in the list. Prints ALL nodes with expectedDate.
NOTE: print methods call Node.toString() as necessary.
NOTE: If no output is generated, your program prints 0 on the console.
The following is the API for the Solution class. This class implements the main method, makes appropriate
data Input/Output calls and implements data structures and all necessary method calls.
Solution
//Attributes NA
main()
Description
Not applicable
Implements the main method; reads data from console, processes information
and make appropriate calls as necessary.
When your program starts, it reads a set of commands (each on a separate line) followed by some input
(optional) from the console and generates appropriate output, to be displayed on the console.
The command takes an integer value 1, 2, 3, 4, 5, 6 or 7. This table shows what each command does.
Command
Meaning
1
Read data from console and save in the data structure
2
Remove data from the data structure
3
Compute the earning of an employee for all packages
4
Compute the earning of an employee per month
5
Print nodes with a certain eID on the console
6
Print nodes with a certain packageID on the console
7
Print nodes with a certain expectedDate on the console
The following shows a sample input and output of your program.
Sample Input
Here is a sample input
1 1225 101 10092021 7 Ahmed Sameh Mohammad
1 1226 102 10092021 4 Ahmed Mohamed
1 1227 103 22022022 5 Ahmed Baloshi
1 1228 103 14022022 3 Ahmed Baloshi
1 1229 101 09012022 4 Ahmed Sameh Mohammad
3 101
4 103 02
2 103
5 101
2
Sample Output
For the above sample input, the following would be printed on the console.
55
40
1229 101 09012021 4 Ahmed Sameh Mohammad
1225 101 10092021 7 Ahmed Sameh Mohammad
Explanation
1 1225 101 10092021 7 Ahmed Sameh Mohammad
1 1226 102 10092021 4 Ahmed Mohamed
1 1227 103 22022022 5 Ahmed Baloshi
1 1228 103 14022022 3 Ahmed Baloshi
1 1229 101 09012022 4 Ahmed Sameh Mohammad
For command 1, your program reads:
The line starting with integer 1 indicates that insert call would be made. No Output is generated for the
insert call. Your program prepares 3 nodes containing information for each ticket. The first node
contains:
packageID=1225
eID=101
expectedDate=10092021
nItems=7
eName=”Ahmed Sameh Mohammad”
Once the node is created, it is inserted into the SList.
Similarly, the other nodes will be created for “Ahmed Mohamed” and “Ahmed Baloshi” and inserted in the
list. Note that insertion should have a proper ordering as explained earlier based on the date.
3 101
The line starting with integer 3 indicates that earning method in the SList would be called. The program
computes the earning for all the packages delivered by the employee with the eID=101. Currently in the
list, there are 2 nodes with eID = 101.
Node with tripID=1225 on date=10092021 has nItems=7 earns = 7 * 5 = 35
Node with tripID=1229 on date=09012021 has nItems=4 earns = 4 * 5 = 20
Hence total earning for eID=101 is 35+20 = 55
55 will be displayed on the console
4 103 02
The line starting with integer 4 indicates that earningPerMonth method in the SList would be called. The
program computes the earning for the trips for the employee with the eID=103 during the month=02.
Currently in the list, there are 2 nodes with eID = 103 and both of them are in the specified month.
Node with tripID=1227 on date=22022022 for nItems=5 earns = 5 * 5 = 25
Node with tripID=1228 on date=14022022 for nItems=3 earns = 3 * 5 = 15
Hence total earning for eID=103 in the specified month is 25+15 = 40
40 will be displayed on the console
2 103
The line starting with integer 2 indicates that the first node with eID=103 will be removed from the list.
No output is generated. This removes the node that contains the following information
1228 103 14022022 3 Ahmed Baloshi
Note: 14022022 appears before 22022022 in the list (starting at head), so it will be removed.
5 101
The line starting with integer 5 indicates that All employee details for eID=101 will be printed on
console separate by new line character at the end of each line.
1229 101 09012021 4 Ahmed Sameh Mohammad
1225 101 10092021 7 Ahmed Sameh Mohammad
Note: Node with expectedDate=09012021 should appear before the node with expectedDate=10092021
Similar to the above, your program implements the following commands:
Legend for the acceptable commands:
1. insert details for a new node
3
2. removes node from list
3. computes the earning for an employee with eID of ALL packages and displays the total.
4. computes the earning for an employee with eID of the pacakegs of the specified month and displays the
total.
5. prints All nodes with eID.
6. prints ALL nodes with packageID.
7. prints ALL nodes with expectedDate.
NOTE: If no output is generated, your program prints 0 on the console.
4
Grading Rubric & Evaluation:
You are allowed to work as a group with maximum 2 members in a group. Your work’s evaluation
would be based on Code inspection and successful execution of k number of test cases. The instructor
reserves the right to determine the scores of each test case.
The project will have two challenges posted on Hackerrank. The first challenge provides an orientation to
hackerrank environment and students earn 5 points (/100) for completing the challenge.
The 2nd challenge is worth 95 points. Students can earn a max of 95 points by completing the test cases.
Students need to complete both challenges.
Any submission on any medium other than Hackerrank will not be accepted. In order for the submission to
be considered, it has to be through Hackerrank. Students who submit via email, LMS or any other means
other than Hackerrank will not be considered.
Code Inspection:
The instructor reserves the right to inspect a submitted code. Generally, a readable code (indentation, clear
scope definition) is required. For this project, there are no limitations on time and memory usage.
Submission Dead-Line:
The submission deadline is final. Late Submissions will be awarded ZERO points.
Plagiarism:
Be warned, all code submitted would be compared using hackerrank.
Any similar code (50% or more similarity) would result in ZERO earned for both students in the
group as well as all the students in the other groups with similar code. NO EXCEPTIONS!
Important Notes:
• It is the student’s responsibility to check/test/verify/debug the code before submission
All submission is through hackerrank. The project URL is www.hackerrank.com/s221cs210
•
•
•
•
•
•
It is the student’s responsibility to safe guard his/her code. If the code is shared with another
group (or student) for any intent; and the code is identical (50% or more similarity), both
students of all groups with similar code will receive ZERO and a Written Warning by the
instructor.
For this project, 2 sample test cases are provided to verify the execution of your program (on hacker
rank).
After an assignment/project has been graded, re-submission with an intention to improve an
assignment score will not be allowed.
You / your team are allowed to submit to hackerrank as many times as you wish before the
submission deadline.
It is highly recommended that students work directly on Hackerrank rather than they work on
NetBeans or another platform and copy the code to Hackerrank as this will create some issues due to
the different environments.
Some Students claim that their code is working on NetBeans but not on Hackerrank. This article
provides the reasons: https://help.hackerrank.com/hc/en-us/articles/115015654848-Why-does-mycode-work-fine-on-my-machine-but-not-on-HackerRank-
5
Submission Guidelines:
Submission on Hacker Rank
Step 1.
Register on https://www.hackerrank.com/
Step 2.
Go to settings
Step 3.
Create a Team. For this project you may work alone (1 person per team) or up to 2 persons per team.
Step 4.
Edit Team details.
1. Create a UNIQUE Team NAME as follows. Each team is composed of 2 students. Use the Student ID and
Instructor Name to build your team NAME
Example: Assume the student IDs for two students is:
Student1 ID: 210110369
Student2 ID: 212110439
Your instructor is Dr. Sawsan Alhalawani,
your team’s name will be: S369S439; here 369 is the last-three-digits of Student1 ID, 439 is the last-threedigits of Student2 ID.
Note: If you are working alone, your team ID will be: S
S221CS210”
2. Join contest “
Step 5:
Go to www.hackerrank.com/s221cs210
Start working on your project.
6