The code below is to create a deterministic finite automata. It just builds the logic of a dfa. The gui can be created very easily.
import javax.swing.JOptionPane;
import javax.swing.*;
import java.util.*;
public class dfa {
static String alphabet,son,retrn;
static int comma=0;
static int acomma=0;
static int number=0;
static String[][] st=new String[50][50];
public static void main(String args[]){
alphabet=JOptionPane.showInputDialog(null,"Alphabet?");
for( int i=0; i
comma++;
}
String states=JOptionPane.showInputDialog(null,"# of states");
number=Integer.parseInt(states);
for(int i=0; i
for(int j=0; j<(alphabet.length()-comma);j++)
{
st[i][j]=JOptionPane.showInputDialog(null,"q"+i+","+alphabet.charAt(k));
System.out.print("q"+i+"--"+alphabet.charAt(k)+"-->"+"q"+st[i][j]+"\n");
k=k+2;
}
}
String start = JOptionPane.showInputDialog(null,"starts state?");
int start1=Integer.parseInt(start);
String accept = JOptionPane.showInputDialog(null,"accept states?");
for( int i=0; i
acomma++;
}
int[] accepts= new int[(accept.length()-acomma)];
int l=0;
for(int i=0; i<(accept.length()-acomma); i++){
accepts[i]=Integer.parseInt(Character.toString(accept.charAt(l)));
l=l+2;
System.out.print(accepts[i]);
}
System.out.println("start state"+start);
System.out.println("Accept state"+accept);
String strng=JOptionPane.showInputDialog(null,"String?");
System.out.println(strng);
int[] durums=new int[strng.length()];
for(int i=0; i
durums[i]=dfa(start1,strng.charAt(i));
}
else{
durums[i]=dfa(durums[i-1],strng.charAt(i));
}
System.out.println(durums[i]);
}
int kontrol=durums[(strng.length()-1)];
int kabuluzun=accepts.length;
for(int i=0; i
System.out.println("ACCEPTED!!!");
break;
}
else if(kontrol!=accepts[i]){
System.out.println(" NOT ACCEPTED!!!");
break;
}
}
//DFA METHOD!!!
public static int dfa(int durum, char deger ){
int deger1=0;
int sondurum=0;
for(int i=0;i
if(deger==alphabet.charAt(i)){
deger1=i;}
else{
for(int j=0; j<(alphabet.length()-comma-1);j++){
i=i+2;
if(deger==alphabet.charAt(i)){
deger1=i-1;
break;
}
}
}
sondurum=Integer.parseInt(st[durum][deger1]);
}
return sondurum;
}
}
Monday, May 26, 2008
DFA logic - Dterministic Finite Automata
Thursday, May 8, 2008
Little Holiday
since i got a problem with my PC it take too much time to add a new article. Also my exams has taken my to much time as well. So by tomorrow i will add everyday again. Soryy about that holiday :))
Friday, April 11, 2008
Linear Algebra - Sytems of linear equations
Here are some linear algebraic questions :P These are the question and will send their solution at next article.
1.Which condition must be placed on a, b, and c so that the following system of equations has a solution?
2. Determine if the given system has a nonzero solution.
3. Determine the values of a so that the given system of linear equations has (i) no solution,(ii) more than one solution, (iii) unique solution.
4. Consider the system of linear equations. Suppose that the system has only the trivial solution when all bi are zero. Show that this system has a unique solution for every other choice of the constants bi.
Thursday, April 10, 2008
Php Code for Membership Panel
These, the codes below is the part of an HTML code for the form of member login.
here is the starting point of the php codes:
ob_start();
include "baglantidosyasi.php";
/* First we get the inğut datas by POST method. */
$kullanici=$_POST["kullanici"];
$sifre=$_POST["sifre"];
$sifrelisifre=md5($sifre); /* Burada Sifreyi md5 leyelim */
/*We are checking username and the password if they are empty */
if(($kullanici=="")or($sifre=="")){
echo "Please do not enter space!!!";
}else{
/*If the pasword and the username is not empty*/
$uyesor=mysql_query("select kullanici,sifre from uyelik where kullanici='$kullanici' and sifre='$sifrelisifre'");
if(@mysql_num_rows($uyesor)>0){
echo "
Welcome $kullanici
";
setcookie("kullanici",$kullanici);
echo "Please Click For Backward HomePage";
}else{
echo "Not Success!...";
}
}
?>
ob_start();
/*Let's check out the cookies if they are empty then the enterance screen will appear*/
$cookie=$_COOKIE["kullanici"];
if($cookie==""){
echo 'Üye Ol | Üye Girişi Yap | ';
}else{
$tarih=date("d/m/y");
echo "Welcome $cookie | Now Date $tarih ";
}
?>
Baglantidosyasi.php
$hostadresi="localhost";
$kullaniciadi="";
$sifre="";
$ad="";
$dbadi="uyelik";
@$baglan=mysql_connect($hostadresi,"root","") or die ("Mysq Bagalkanadmi");
@mysql_select_db($dbadi,$baglan) or die ("vt Bagalkanadmi");
?>
Try to decode =))
Good Luck!!!
Tuesday, April 8, 2008
Design Report of a Dynamic Website
We choose Waterfall model because it gives the benefits of feedbacks that are very effective. This software development life-cycle model enhanced with the integral processes given below in Drawing.
Sequence Diagram for dynamic website:
Scenario:
We have an project file to be uploaded in the projects part.
To do this process, firstly we need to log in with and admin username and password. Checking out login process from users table at the database.
Having done that, then the control panel for admin will be displayed.
By using control panel, admin will upload the file from his/her own PC to the projects part of the website.
Comunication Diagram
Our comunication diagram has the same scenario with the sequence diagram above. It does not shows the liftime of the messages, instead it shows the interaction between the processes.
Sunday, April 6, 2008
Explanation of the Database Creation Code
Firstly as you have seen at the article from this one we have created 4 tables : report, employee, factory, part to store the datas.
--> Why we use dbms? We use them to store the datas in a tidy fashion. I mean assume that you are storing the entire data in the same file. In this condition you need to read all the file and try to get the data you need to use. Since we want to access the desired datas in an acceptabşe time period we need to use database systems. I think it is clear enough why we created 4 tables(dividing the entire data).
Then, in the code piece
create table report(
report_ssn int not null,
primary key (report_ssn))
We are creating the table report and we are saying that we gone store in this tale te report_ssn in iteger type and it is the primary key of our table.
--> What is primary key? Primary keys are the special fields in the table which are uniquely identifies a data in that table. For instance if i am storing your and my other friends' names ssn_nos and surnames in a table called friends, then i can find out your informations by typing your ssn number since it uniquely identifies you.
In this code piece
create table employee (
ssn int not null,
e_name varchar(20) not null,
salary int not null,
report_ssn int not null,
fac_id int not null,
primary key (ssn),
foreign key (report_ssn)references report(report_ssn))
We are creating the table employee and storing the required datas in the fields. We set our ssn field as primary key and report_ssn field from report table as foreign key.
-->What is foreign key?Foreign keys are used to combine two related tables. I mean if i want to know which employee report whom i combine the tables employee and report with a foreign key. A foreign key can be created if it is a primary key in which table we want to combine and if there is a limitation as at most one!
In this piece of code
alter table employee add
foreign key(fac_id) references factory(fac_id)
We are altering the table amployee. We are adding a foreign key from the table factory to combine two tables.By using the code 'alter table' you can add or delete some fields from the tables as well.
Whit these explanations you can examine the code i have written in the article before:))
Good Luck!!!
Friday, April 4, 2008
Creating Database System (DBMS)
Here is the question below! We will create a database according to these criterias:
You have just been hired as a consultant for a big airplane manufacturer. They want you to completely redesign their database system. Talking with the people in the company, you get the following information.
1-The database contains information about employees, factories and parts.
2-Each employee has a social security number (SSN), name and salary. An employee is uniquely identified by his/her SSN.
3-Each factory has an id, a name and a budget. The id uniquely identifies a factory.
4-Each part has an id and a name. The id uniquely identifies a part.
5-Each employee reports to at most one other employee.
6-Each employee works in at least one factory.
7-Each part is manufactured in exactly one factory.
Here is the answer of the question:
create table report(
report_ssn int not null,
primary key (report_ssn))
create table employee (
ssn int not null,
e_name varchar(20) not null,
salary int not null,
report_ssn int not null,
fac_id int not null,
primary key (ssn),
foreign key (report_ssn)references report(report_ssn))
create table factory (
fac_id int not null,
fac_name varchar(20) not null,
budget int not null,
ssn int not null,
primary key (fac_id),
foreign key (ssn)references employee(ssn))
create table part(
part_id int not null,
part_name varchar(10) not null,
fac_id int not null,
primary key (part_id,fac_id),
foreign key (fac_id) references factory (fac_id))
alter table employee add
foreign key(fac_id) references factory(fac_id)
Try to decode the code above firstly! I will explain the code at the next article (=
Hint: Since i could not captured the fac_id foreign key into the employee table when i am creating i added the foreign key by alter table.I could not captured that foreign key first since the table factory and the table employee include each other's primary key as foreign key.So i needed to create factory table first and than add the foreign key by alter table.