Wednesday, June 30, 2010

ECP4136 tut 3 part 1

import java.awt.*;
import javax.swing.*;
import java.util.*;

public class test
{
public static void main (String[] args)
{
JFrame frame = new JFrame ("Funky Panels");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

ImageIcon icon = new ImageIcon ("Launch.gif");

Random generator = new Random();
float num1, num2, num3;

num1 = generator.nextFloat();
num2 = generator.nextFloat();
num3 = generator.nextFloat();

JLabel label1,label2, label3, label4;

label1 = new JLabel ("Sine(" + num1 + ") = " + Math.sin(num1), SwingConstants.CENTER);
label2 = new JLabel ("Cosine(" + num2 + ") = " + Math.cos(num2),SwingConstants.CENTER);
label3 = new JLabel ("Tangent(" + num3 + ") = " + Math.tan(num3),SwingConstants.CENTER );
label4 = new JLabel (icon, SwingConstants.CENTER);





JPanel subpanel1 = new JPanel();
subpanel1.setPreferredSize (new Dimension (400,100));
// subpanel1.setBackground (Color.green);
subpanel1.add (label1);
subpanel1.add (label2);
subpanel1.add (label3);

JPanel subpanel2 = new JPanel();
subpanel2.setPreferredSize (new Dimension (200,100));
// subpanel2.setBackground (Color.red);
subpanel2.add (label4);


// Set up primary panel
JPanel primary = new JPanel();
primary.setBackground (Color.yellow);
primary.setPreferredSize (new Dimension (800,250));
primary.add (subpanel1);
primary.add (subpanel2);
// primary.add (label3);


frame.getContentPane().add(primary);
frame.pack();
frame.setVisible(true);
}
}

Saturday, June 26, 2010

attempt #2 : redesign blog templates

short note:
wat happen to attempt #1? i din save haha, looks ugly anyway~

********************************************************************************************

After trying so many different designs given by Blogger...original one still best =.=!! All their design dun hav tat "feel" i'm looking for, sad~ next time will try other websites and try~ for now I think I'll just leave it alone like tis, quite stressful keep design fail haha.

Tuesday, June 22, 2010

ECP3076 tut2

1. Key defines entity relationships. Primary key, secondary key, foreign key, superkey, candidate key.
2. …
4. SELECT, PROJECT, JOIN, INTERSECT, UNION, DIFFERENCE, PRODUCT, and DIVIDE, same commands. Note* SLECT in relational algebra only means selecting entities from an entity set, while SELECT in SQL is a command that has much wider use.
5. PRODUCT produces a list of all possible pairs of rows from two tables.
SELECT yields values for all attributes found in a table. It yields a horizontal subset of a table. (command: select * from table1, table 2)
PROJECT produces a list of all values for selected attributes. It yields a vertical subset of a table
6. all joins are implemented with SELECT. The difference is in the WHERE clause. With a natural join, you are always comparing attributes with the same name, using the = comparison
Select * from table1, table2 where table1.t1_ID = table2.t1_ID
An equi join, u use table columns which are permitted to be different, but still with the = comparison
Select * from table1, table2 where t1_ID = t1_ID
A theta join is where the comparison operatior may be some other thing
Select * from table1, table2 where T1_A < T1_B


Section B
b. DIR_NUM
c. 1 to many, no
d. The foreign key must hav a null value or matches primary key values in the PLAY TABLE.
The PLAY table has a foreign key which is the primary key of the DIRECTOR table. Entering data into the PLAY table requires that the foreign key hav a matching value to the PK of the DIRECTOR table. This ensures that a PLAY must be directed by a listed/recorded director in the database else it must be left null (it is possible for a play to exist without a director..)

Part C:
create database test;
connect to test;
create table student1
(
stud_id char(10) not null,
stud_name varchar(50),
stud_hometown varchar(50),
stud_state varchar(50),
stud_religion varchar(50),
stud_birthday date,
primary key (stud_id)
);

insert into student1 values ('1071112489', 'Edwin', 'Batu Berendam', 'Melaka', 'Buddhist', '1989-03-25');
insert into student1 values ('1061111659', 'Adrian', 'Sin Hoe Garden', 'Melaka', 'Buddhist', '1989-07-07');

select * from student1;
select * from student1 where stud_name = 'Edwin';

create table student2
(
stud_id char(10) not null primary key,
stud_name varchar(50),
stud_hometown varchar(50),
stud_state varchar(50),
stud_religion varchar(50),
stud_birthday date
);

Tuesday, June 15, 2010

ECP3076 tut 1

1. Describe the different ways a DBMS can be classified.
• No of users, locations, expected type and extend of use

2. A relational database differs from network and/or hierarchical databases in what aspect(s)?
- Physical structure closely resembles the logical structure.
- The relational DBMS handles most physical details.

3. Describe the basic features of the relational data model and discuss their importance to the end user as well as the designer.
- The relational data model illustrates end user data as beong stored in tables. Each table is a matrix consisting of a series of row/column intersections. Tables also called relations are related to each other by sharing of a common entity characteristic (value in a column). The relational database is perceived by the user to be a collection of tables in which data are stored. The relational data model allows the designer to focus on how the data components interact rather than on the physical details of how the data are store. The makes much easier to model the complex real world data environment.

4. Explain structural independence and its importance in data management.
- In terms of data management, structural independence means that the way the data is stored will have no effect on the programs that use it. In other words, any changes to the file structure will not effect existing programs that access the data stored within the file structure. File system data management is an example of data structure that does NOT show structural independence – program access is tied tightly with how data is stored. DBMS structures support better structural independence as the user no longer need to know where/what is used to store the data but only how to access it.

a) What problems can you identify with the data file structure shown above? How can they be corrected?
- Table shows data from 2 separate ‘objects’ – projects and managers, results in redundant copies of data which increase occurrence of data anomalies – insertion, deletion and update anomalies. At current structure, multiple copies of same data MUST be created even though real life the relationship does not exist such as:
- 1. A new manager in the company can only be inserted once he/she is assigned a project.
- 2. Projects must have a manager at time of data insertion into the table.
- 3. Other employee data is not listed as project members except the manager.
- 4. If Holly gets married, her last name has to be changed three times (update)
- 5. Information about “William K. Moor” will be lost if his row is deleted. (delete)
- To correct the problems the file structure can be subdivided into simpler files, each representing a single subject – i.e. Normalization.