Csc 1302, Honors Principles of Computer Science II (Fall 2016)

Week 8 (13 October 2016)

Select Operator

During this week you will write the following methods:
  1. (Tuple.java):
    // This method takes a comparison condition in the 5 parameters and
    // returns true if the tuple satisfies the condition and false otherwise.
    //
    // The comparison condition is coded in the 5 parameters as follows:
    //
    // lopType/ropType can take one of three values: "col", "num", "str"
    // indicating that the operand is either a name of a column, or a number,
    // or a string respectively.
    //
    // lopValue/ropValue will contain the name of the column if the lopType/ropType
    // is "col" and will contain a numeric value if lopType/ropType is "num" and
    // will contain a string value if lopType/ropType is "str".
    //
    // comparison will have one of six values: "<", "<=","=",">",">=", or "<>"
    //
    // As an example, if we want to express the comparison, SNAME = "Jones", the 5 parameters will be:
    // lopType="col", lopValue="SNAME", comparison="=", ropType="str", ropValue="Jones"
    //
    // As another example, if we want to express the condition GPA > 3.0, the 5 parameters will be:
    // lopType="col", lopValue="GPA", comparison=">", ropType="num", ropValue="3.0"
    //
    public boolean select(String lopType, String lopValue, String comparison,
                          String ropType, String ropValue) {
      // Top level cases to consider:
      //
      // lopType="num" and ropType="num"
      // lopType="str" and ropType="str"
      // lopType="col" and ropType="num"
      // lopType="col" and ropType="str"
      // lopType="num" and ropType="col"
      // lopType="str" and ropType="col"
      // lopType="col" and ropType="col"
     
    }
    
    
  2. (Relation.java) Select Operator:
    // This method takes as input a comparison condition as explained earlier and returns
    // a new relation that contains only those tuples that satisfies the comparison condition.
    public Relation select(String lopType, String lopValue, String comparison,
                           String ropType, String ropValue)
    

Download the Driver Programs and implement all the methods in this assignment. Compile and run the driver programs. You should see the following output when you run DriverW8.java:

[raj@tinman w4]$ java DriverW8
STUDENT(SID:INTEGER,SNAME:VARCHAR,PHONE:INTEGER,MAJOR:VARCHAR,GPA:DECIMAL)
Number of tuples: 4

1111:Robert Adams:1234:Computer Science:4.0:
1112:Charles Bailey:5656:Computer Science:3.5:
1113:David Beatle:1212:Mathematics:3.5:
1114:Graham Gooch:5678:Computer Science:3.5:

SELECT_SID_=_1114(SID:INTEGER,SNAME:VARCHAR,PHONE:INTEGER,MAJOR:VARCHAR,GPA:DECIMAL)
Number of tuples: 1

1114:Graham Gooch:5678:Computer Science:3.5:

SELECT_GPA_>=_3.5(SID:INTEGER,SNAME:VARCHAR,PHONE:INTEGER,MAJOR:VARCHAR,GPA:DECIMAL)
Number of tuples: 4

1111:Robert Adams:1234:Computer Science:4.0:
1112:Charles Bailey:5656:Computer Science:3.5:
1113:David Beatle:1212:Mathematics:3.5:
1114:Graham Gooch:5678:Computer Science:3.5:

SELECT_MAJOR_=_Computer Science(SID:INTEGER,SNAME:VARCHAR,PHONE:INTEGER,MAJOR:VARCHAR,GPA:DECIMAL)
Number of tuples: 3

1111:Robert Adams:1234:Computer Science:4.0:
1112:Charles Bailey:5656:Computer Science:3.5:
1114:Graham Gooch:5678:Computer Science:3.5: