Вы находитесь на странице: 1из 2

CS210 with Dr.

Basit Qureshi

Term Project 3

Weight 5%

Due: End of December 7, 2016 (23:59)

CreditCard Transactions Log Processor


This project will allow you to write a CreditCard Transactions Log processor system that creates logs of transactions
against various credit cards. This project intends to fortify your concepts in Hash tables with separate chaining. As part
of this project you would be writing new code as well as re-using some of the code previously written. The following
classes need to be written: Tester, CCNode and CCLogger. The hash table is implemented with class CCLogger, which
stores an array of Ten (10) references of type CCNode that imitate as heads for the linked chains.
CCLogger

0
CCNode

CCNode

CCNode

CCNode

Use the following API to write the CCNode class


public class CCNode
long CCNumber
double CLimit
double Balance
CCNode next
String Log
#
#

//stores this Credit Card number of this person


//Holds Credit Limit. Max withdrawable amount
//Holds the current Balance
//Holds reference to the next PersonNode
//Writes record of all transactions

CCNode()
get()
Set(,)

//appropriate constructors
//appropriate get methods
//appropriate set methods

Use the API to write the CCLogger class


public class CCLogger
CCNode [] HashTable
int size
int
void

CCLogger()
getHash(Key)
Add(#)
Credit(Key, Amt)
Debit(Key, Amt)
getLog(Key)

//maintains the Hash Table of size 10


//maintains the number of items in the Hash Table
//appropriate constructor
//Returns a hash value for Key
//Adds a new CCNode with appropriate details (#)
//Updates the Balance (subtract Amt) against the Key
//Updates the Balance (add Amt) to CCNode for Key
//Returns Log information for a Key

Details for some of the above mentioned methods are as follows:


The Hashing method.
The getHash method takes the Credit Card number as a Key and generates a hash code using the following details.

4507112832632843

CreditCard number must be 16 digits long.


Hash Code is generated by adding the highlighted digits (red) and taking mod 10 of this sum. In above example
(7+8+3+3) %10 = 21 %10 = 1

This indicates that the above CreditCard must be added to HashTable[1]s chain.
The getLog method
Everytime the Add, Credit, Debit methods are called the following information needs to be added to the Log in the
CCNode object.
Current_Time

CCNumber

CLimit

Balance <nextLine>

The getLog method returns String obtained from the Log variable in the CCNode object. You can obtain the
Current_Time by calling System.currentTimeMillis()/1000;

The Add method


Takes CCNode object as parameter. Verifies if another node with the same CreditCard information does not exit
(Duplicates are not allowed) and adds to the beginning of the hashtable[i] chain (similar to
LinkedList.AddToFront()). If a duplicate exists, an error is generated.
The Credit method
Takes Key and amount as parameters. Looks up for a CCNode object with the same key and deducts (subtracts) the
amount from the balance. If the amount is less than the Balance then display appropriate error message.
The Debit method
Takes Key and amount as parameters. Looks up for a CCNode object with the same key and adds the amount to the
balance. If the total after debit is larger than the credit limit, display a Warning message.
The Tester Class
Write a Tester Class that creates an object Logger of type CCLogger. The tester program reads input from console
and calls appropriate methods of the Logger object. Following explains the input format:
1 2134332454231234 15000.0 15000.0
Explanation: 1 means add Credit card 2134332454231234 with credit limit 15000 and Balance 15000
2 2134332454231234 12345
Explanation: 2 means Credit amount 12345 from the balance of credit card 2134332454231234
3 2134332454231234 1240
Explanation: 3 means add amount 1240 to Balance of Credit card 2134332454231234
4 2134332454231234
Explanation: 4 means show log details for credit card 2134332454231234

All the inputs are organized on separate lines. The output of option 4 must be organized as follows
Current_Time CCNumber CLimit Balance
Current_Time CCNumber CLimit Balance
Current_Time CCNumber CLimit Balance
.
.

Evaluation:
You are allowed to work in a group of up to 2 students. The score earned would be given to both team members
equally. Your works evaluation would be based on Code inspection and successful execution of N number of test
cases. The instructor reserves the right to determine the scores of each test case.
Code Inspection:
The code would be inspected by the instructor. Advanced tools would be used to check for plagiarism cases.
Submission:
Your group needs to submit two files, a Jar file and all code in a zip file. Beware (attach only .java files, .class files
cannot be read). The file names must be your id. For group submission, the filename must be FirstID_SecondID
All submissions through LMS (http://lms.psu.edu.sa)
Plagiarism:
Be warned, all code submitted would be compared using hackerrank. Any similar code would result in ZERO
earned for both group members as well as all other groups with similar code. NO EXCEPTIONS!

Вам также может понравиться