trying to write a java class named Algebra that will have static methods representing the relational algebra and one additional method which displays the contents of a tilde table and works with any tilde table. table will have the following attributes and limitations:
-at most 12 columns
-first row represents column names
-all columns are strings
-column values and column names are limited to 16 characters
But cannot load all the rows into an array or other collection. All methods except for the display method return a string indicating success or an error message and for every successful operation a new tilde table is produced on disk. So I need to write the method to show the table, the project operation, the join operation, the restrict operation (restriction condition can be limited to a single condition (so no ANDs and ORs) and comparitors can be limited to these six: =, >, <, >=, <=, !=).
So the main body of a driver program might look like this:
//restrict the cars table to toyotas producing a table named toyotas
Algebra.Restrict("cars","MAKE='Toyota'","toyotas");
//project just three columns from the toyotas table producing a table named answer
Algebra.Project("Toyotas","Make,Model,Price","answer");
//display the contents of the answer table
Algebra.Display("answer");
output would be:
MAKE MODEL PRICE
---------------- ---------------- ----------------
Toyota Camry 18000
Toyota Tacoma 19000
Toyota Highlander 35000
cars.txt file containing the tilde table
MAKE~MODEL~TYPE~PRICE
Toyota~Camry~Sedan~18000
Toyota~Tacoma~Truck~19000
Ford~Mustang~Sport~21000
Chevrolet~Corvette~Sport~48000
Ford~F150~Truck~25000
Toyota~Highlander~SUV~35000
What I have so far
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Algebra {
public void readData() throws FileNotFoundException, IOException{
BufferedReader in = new BufferedReader(new FileReader
("cars.txt"));
String line;
while((line = in.readLine()) !=null){
System.out.println(line);
}
in.close();
}
/*Method used to restrict data--Using WHERE clause*/
public void Restrict(){
}
/*Method used to project data--Using SELECT clause*/
public void Project(){
}
/*Method used to join the data--Using JOIN clause*/
public void Join(){
}
/*Display results from combination of previous methods*/
public void Display(){
}
}