******I need help with my project. Here's the specs**********
CS123 MP2
Database Table
1. On Load of the program it will read all files and put its data to the memory.
a. Data file - this must be in CVS (Comma Separated Values). The first line
is a header that contains the field names.
b. Index File(s) - I leave it up to you how you will store the AVL into a
file. Remember that you need to create the AVL from the file when the program
is first started.
Note : Windows and Linux have different file separator character. Your program
must be able to run on both Windows and Linux. Use the File.separator.
2. The program must be able to do the following
a. Add a record
b. Update a record
c. Delete a record
Note: I leave it up to you how the program will ask for field values. In the
case of update and delete where you need to know which record to update or
delete. The program should ask for an int value, which corresponds on the
position of the record on the file.
e. Search a record - User may specify any number of search criterias, joined
or or and. Note that and will always take precedence over or. Suppose the
following search criteria is formed, S1 and S2 or S3 or S4 and S5, then this
is the order of performing the search. (S1 and S2) or S3 or (S4 and S5). A
search criteria is made up of the following. a Field, an operator (=, >, >=, <, <=)
and the Field value. I leave it up to you how you will ask the user.
f. Create an index on a field - creates an AVL Tree on the values of on all
of the records on the specified field. Note that an index changes how the
whole data base works. If a record is added or deleted, the index must also
be updated to reflect the addition or the loss of the record. If the record
is updated, you need to perform a delete then an add on the AVL Tree. The
existence of an index field, should change the way you search for records.
If the index is available, you need to use it.
g. Drop an index on a field - removes the index in memory.
h. Save Changes unto a file (or files as needed).
3. Program must keep on running until the user chooses to exit the program.
Additional notes:
Use the HashMap or Hashtable as your record. An ArrayList containing your
records (HashMap) will serve as your in memory data structure to keep track
of all the records.
To avoid confusion I will call the record index as (RI) and the indexes on the
field as Field Index (FI).
The RI will serve as the index to your array list for easy access. In your
FI you need to store the RI's along side the Field value.
For example I have the following records.
FirstName,LastName,StdNo
Jose Marciano,Patino,99-60088
Benjamin,Herrera,99-12564
Che Ann,Alib,99-78945
Erik,Bulatao,99-01011
And I have an FI on LastName,
the AVL will look as such: Herrera (1)
/ \
Alib(2) Patino (0)
\
Bulatao(3)
Note that rotations have been performed on the AVL already to keep it balanced.
This means if i have to search "Bulatao" I just traverse the AVL. Retreive
the index (which is 3) then use it to access th ArrayList. Do not allow
duplicates on your AVL instead you just add the RI to the node
Suppose I will add the record:
Juan Bernardo,Patino,05-54236
The AVL will look as such: Herrera (1)
/ \
Alib(2) Patino (0, 5)
\
Bulatao(3)
Some other things to consider. Notice that all if you delete a records from
the ArrayList it performs shift on the array. Meaning the RI's on the AVL
needs to be updated. Also note that Suppose I am to delete record 5. The AVL
should not automatically delete the node containing "Patino" since the it
still has an RI.
You need to delete only the RI on the node, once you have deleted all RI's on
the node then that is the time that you will proceed with the removal of
the node. This should also be the case for update.
Things to consider when searching.
Suppose my search criteria is LastName <= Herrera. I first traverse the AVL
to Herrera node, then create a set containing all the RI's on the left Sub
tree of Herrera node and all the RI's on the Herrera node (since = is also
specified).
The harder question is actually what if Herrera does not exist on the AVL?
I leave that question for you to answer. Good luck on your MP.
******Here's what I've done so far..*************
>>>>>>>>>>>>>>>>>Class DBRecord<<<<<<<<<<<<<<<<<<
import java.util.*;
public class DBRecord {
public HashMap hashMap;
public ArrayList dbHeaders;
//constructor
public DBRecord(ArrayList headers, String[] values){
hashMap =new HashMap();
for(int i=0; i>>>>>>>>>>>>>>>>Class DBTable<<<<<<<<<<<<<<<<<<
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DBTable {
private JFrame frame;
private JPanel panel1,panel2, panel3;
private JTextField fields;
private JLabel labels;
private JButton ok, reset, back;
public static ArrayList dbHeaders;
public static ArrayList dbTable;
public ArrayList popList1, popList2;
public static DBRecord record;
static String[] values;
static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
//constructor
public DBTable(ArrayList headers){
dbTable = new ArrayList();
dbHeaders = headers;
}
//returns size of dbTable
public int size() {
return dbTable.size();
}
//returns list of fields
public ArrayList getField(){
return dbHeaders;
}
//adds a record into dbTable
public void add(DBRecord record){
dbTable.add(record);
}
public DBRecord get(int index){
return dbTable.get(index);
}
//prints contents of text file
public void printRecord(){
//System.out.println("*********************************************");
//System.out.println("Printing Records..");
//System.out.println();
for(int i=0; idbTable.size()){
JOptionPane.showMessageDialog(null,"Index out of bounds!");
}else if(index<=dbTable.size()){
dbTable.remove(index);
}else{
JOptionPane.showMessageDialog(null,"Bad input!");
}
}
//updates record
public void updateRecord(){
try{
String recKey;
String newValue;
recKey=JOptionPane.showInputDialog("Enter record number: ");
int recordNumber = Integer.parseInt(recKey);
DBRecord record = dbTable.get(recordNumber);
String[] values = record.toString().split(",");
int choice= displayFieldMenu();
if(choice<=dbHeaders.size()){
newValue=JOptionPane.showInputDialog("Enter value to replace with "+values[choice]+":");
record.put(dbHeaders.get(choice), newValue);
}else{
JOptionPane.showMessageDialog(null, "Error! Bad input!");
}
}
catch(IOException io){
JOptionPane.showMessageDialog(null, "Bad input!");
}
catch(NullPointerException ne){
JOptionPane.showMessageDialog(null,"Null pointer exception!");
}
}
//searches for the particular record then searches for the particular field with conditions
public void searchRecord(){
try{
Object[] array;
Object[] popArray;
ArrayList orList = new ArrayList();
Stack stack = getConditions();
while(stack.size()!=1){
popList1 = (ArrayList)stack.pop();
popList2 = (ArrayList)stack.pop();
orList = implementOR(popList1,popList2);
stack.push(orList);
}
popList1 = (ArrayList)stack.pop();
for(int i=0; i getCriteria(Stack aStack)throws IOException{
String operator;
String fieldValue;
ArrayList intList = new ArrayList();
int choice=displayFieldMenu();
String field=dbHeaders.get(choice);
operator=JOptionPane.showInputDialog("Enter operator: ");
//String operator = input.readLine();
fieldValue=JOptionPane.showInputDialog("Enter field value: ");
//String fieldValue=input.readLine();
intList=getComparison(field, operator, fieldValue);
/*for(int i=0; i getComparison(String field, String operator, String fieldValue){
ArrayList indexSet = new ArrayList();
if(operator.equals("=")){//equals
for(int i=0; i") || operator.equals(">=")){
//greater than or greater than or equal to
for(int i=0; i0 ||
(dbTable.get(i).get(field).compareTo(fieldValue))>=0){
indexSet.add(i);
}
}
}else if(operator.equals("<")||operator.equals("<=")){
//less than or less than or equal to
for(int i=0; i> getConditions()throws IOException{
String condition="";
Stack stack = new Stack>();
ArrayList criteria=new ArrayList();
criteria=getCriteria(stack);
for(int i=0; i)stack.pop();
popList2 = (ArrayList)stack.pop();
stack.push(implementAND(popList1, popList2));
}else{
break;
}
}
return stack;
}
public ArrayList implementOR(ArrayLista, ArrayListb){
int count = 0;
int size = b.size();
while(count != size){
a.add(b.get(count));
count++;
}
for(int i=0; i implementAND(ArrayLista, ArrayListb){
ArrayList list = new ArrayList();
for(int i=0;i
Wow, all that code, and not a code tag to be found.
To be honest with you, no one is going to go through that much code, especially unformatted as it is (use code tags). Try to create a small, self-contained, but complete example that duplicates the problem, and post that code. Many times, creating that example, will result in you finding the solution to your own problem, and hey, that's even better.
he he.. yah i know.. at least u guys know how confused i am as with my code.. thanks nyways. im trying to tone the whole thing down so maybe il repost the code soon...