Csc 1302, Honors Principles of Computer Science II (Fall 2021)
Week 1 (27 August 2021)
Database, Relation, Tuple
Sample Database InstanceDatabase Class: Encapsulates the entire database, which is nothing but a collection of relations (or tables); Variables include:
Map<String,Relation> relations;The key for the map is the name of the relation.
Java Map Documentation
Example - mkyong
Relation Class: Encapsulates a relation or table; includes both schema and instance. Variables include:
// Name of the relation. private String name; // Attribute names for the relation private ArrayList<String> attributes; // Domain classes or types of attributes; possible values: INTEGER, DECIMAL, VARCHAR private ArrayList<String> domains; // Actual data storage (list of tuples) for the relation. private ArrayList<Tuple> table;
Tuple Class: Encapsulates a tuple or row of a relation; includes both schema and instance. Variables include:
private ArrayList<String> attributes; private ArrayList<String> domains; private ArrayList<Comparable> tuple;Java Comparable Documentation
Example - mkyong
TO DO
Download the Skeleton files and implement all the methods in these Java classes. Compile and run the driver program. You should see the following output:
[raj@tinman w1]$ java Driver Database Schema -------- ------ STUDENT(SID:INTEGER,SNAME:VARCHAR,MAJOR:VARCHAR,GPA:DECIMAL) COURSE(CNUM:VARCHAR,CTITLE:VARCHAR,DESCRIPTION:VARCHAR,CREDITS:INTEGER) STUDENT(SID:INTEGER,SNAME:VARCHAR,MAJOR:VARCHAR,GPA:DECIMAL) Number of tuples: 2 1111:Robert Adams:Computer Science:4.0: 1112:Charles Bailey:Mathematics:3.0: COURSE(CNUM:VARCHAR,CTITLE:VARCHAR,DESCRIPTION:VARCHAR,CREDITS:INTEGER) Number of tuples: 2 CSc 1301:Intro to CS I:Java Programming and breadth topics:4: CSc 1302:Intro to CS II:In depth Java Programming and some breadth topics:4: