Você está na página 1de 4

COMP 182L Fall 2017 Project 3

Due Wednesday, October 22nd 2017 23:55 Week 9

Purpose: You are going to learn how to implement a linked list and deepen your understanding
of object-oriented design.

Requirements: To complete this project you will write five classes and one text file.

NOTE: You are creating a Linked List from


scratch. You may NOT use java.util.Vector for
the ordered vector, but you may use
java.util.Scanner as before.

Create a file Account.java which is a class representing a very basic checking account. An
account has a firstName (String), lastName (String), accountID (unsigned integer), and
currentBalance (double). You should create appropriate constructors and accessors/mutators
for each of these values. You should also create a method
public String toString()
o Returns a String in the form accountID, lastname, firstname,
currentBalance
o Example: 481516, Mkrtchyan, Katya, $23.42
Note, monetary values must be printed in the form $DD.cc
Where DD is the dollar amount and cc is the number of cents (0-
padded to 2-digits)

Create a file OrderedVectorOfAccounts.java which is an ordered vector of accounts


sorted by accountID. It will have methods addAccount(Account acct), delAccount(int accountID),
findAccount (int accountID), modifyBalance(int accountID, double adjustment), and toString()
which returns a String of all Accounts, one per line.
*****NOTE: you must use a RECURSIVE BINARY SEARCH function (like the one in Lecture) to
implement findAccount on the OrderedVectorOfAccounts!

Rules of Growth: OrderedVectorOfAccounts should start with a capacity of 20 and grow by 10


elements every time it runs out of space during an addWord operation.

Create a file AccountNode.java. It will hold an instance of an Account as well as a next and
previous pointer (to other AccountNodes). It will have accessors and mutators for next/prev
pointers.

Create a file LinkedListOfAccounts.java which implements a doubly linked list of


Accounts using AccountNode. It maintains a head and a tail pointer. Inserting is done at the end
of the list. It will have methods addAccount(Account acct), delAccount(int accountID),
findAccount (int accountID), modifyBalance(int accountID, double adjustment), and toString()
which returns a String of all Accounts, one per line.
*****NOTE: binary search cannot be used for findAccount here, as this is a linked list, and
unordered.

(Notice that LinkedListOfAccounts and OrderedVectorOfAccounts both hold a list of accounts.


You do have to implement both of them.)

Create a file called Driver2.java which contains a java program. This program will instantiate
an OrderedVectorOfAccounts and a LinkedListOfAccounts, and will read from a file called
accounts.txt to initialize both data structures. Then the program will allow user interaction. See
the same accounts.txt file and user interaction below.

Once you have finished programming and debugging your code, time both data structures using
System.currentTimeMillis(). Try these tests:
inserting 1000 items
inserting 500 items and then deleting each
inserting 1000 items and then performing 10000 finds
Write a file named Analysis.txt where you describe the performance of the
LinkedListOfAccounts and the OrderedVectorOfAccounts on each of these tests. Explain why
you obtain these results.

Suggested Plan Of Attack:


Plan out your classes in detail prior to coding anything. This will reduce the amount of code and
the amount of debugging. Implement OrderedVectorOfAccounts first and test it. Start as soon as
possible and finish programming 2-3 days before the deadline to give time for Analysis.txt

Grade Breakdown:
15%: Submission instructions followed to the letter (5 .java files and 1 .txt file, named as stated
above)
20%: Code compiles without error
30%: Code functions as per this spec
15%: Code has proper indentation, style (~30 line routines, 80 chars per line), layout as per
spec, and comments where appropriate
20%: Analysis.txt contains results of tests and appropriate analysis

Cheating: This project (like all projects in this class) is an individual project. You can discuss
this project with other students. You can explain what needs to be done and give suggestions
on how to do it. You cannot share source code. If two projects are submitted which show
significant similarity in source code then both students will receive an F in the course. Note a
person who gives his code to another student also fails the class (you are facilitating the
dishonest actions of another).

Sample accounts.txt:

This file consists of 4 lines for each account (lastName, firstName, accountID, currentBalance)

Kwon
Sun
77665
408 16
Mkrtchyan
Katya
90210
555 66
Norris
Chuck
75007
998700 20

Sample Interaction:

***assume program starts here***

Welcome to Project 3
Reading data from accounts.txt
Enter a command
> asdfghjk

Not a valid command. Try help.

Enter a command
> help

Commands are:
account (add a new account)
close (remove an account)
find (display one account)
deposit (add money to account)
withdraw (remove money from account)
help (print this screen)
quit (end the program)

Enter a command
> account

What is the owners name?


> John Connor

Created account with number 90211

Enter a command
> find

What is the account number?


> 90210

90210, Mkrtchyan, Katya, $555.66

Enter a command
> close

What is the account number?


> 90210

Katya Mkrtchyan account closed.

Enter a command
> close

What is the account number?


> 90210

Account 90210 not found.

Enter a command
> deposit

What is the account number?


> 77665

What is the amount?


> 2.42

Sun Kwon new balance $410.58.

Enter a command
> withdraw

What is the account number?


> 75007

What is the amount?


> 998699.20

Chuck Norris new balance $1.00.

Enter a command
> quit

Você também pode gostar