Wednesday, September 26, 2012

A Simple Java program for a Car Park System (Code) Part 2


Part 1 (PSEUDOCODE )

CODE



import java.util.*;
import java.util.LinkedList;


class car11{
public static void main(String args[]){

LinkedList <vehicle>list1 = new LinkedList<vehicle>();
LinkedList <vehicle>list2 = new LinkedList<vehicle>();


Scanner in=new Scanner(System.in);
System.out.println("");
System.out.println("\t"+" WELCOME TO LAUGH CAR PARK        ");

System.out.println("");
System.out.println("\t"+"Car Park contains : " + list1);


int inputNum1=0;
int carNum1;
int Num2;
try{

        while(true){
System.out.println("1.Enter Garage\n2.Exit from garage\n3.Display Car List\n4.Exit menu");
inputNum1=in.nextInt();
          switch(inputNum1){
           case 1:
if(list1.size()<=9){
int numOfCars=0;
vehicle vehicleID=null;

for(int h=0;h<list1.size();h++){
vehicleID=list1.get(h);
numOfCars=vehicleID.no;
System.out.println("Car numbers in the Car Park now "+numOfCars);

}System.out.println("");
System.out.println("Car Park has another : " + (10-numOfCars)+" vacansies");

System.out.println("\t"+"...Please come next car...");
System.out.println("");
System.out.println("Car number "+(list1.size()+1)+" is the next to enter garage");
System.out.print("Enter the car number given above ");
carNum1=in.nextInt();

if((list1.size()+1)==carNum1){
list1.add(new vehicle(carNum1));
}
else{
System.out.println("Please enter correct car number ");
}

}
else{
System.out.println("");
System.out.println("Sorry!!!!");
System.out.println("No parking space available.Please wait until a vacancy comes");

     int inputNum2=0;

 for(int h=0;h<list2.size();h++){
System.out.print(list2.get(h).no+" ");
 }
System.out.println("  Cars are waiting to enter garage");
System.out.println("Would you like to enter waiting list???");
         System.out.println("1.yes\n2.no");  
inputNum2=in.nextInt();


switch(inputNum2){
case 1:
System.out.println("Car number "+(list2.size()+11)+" is the next to enter garage");
System.out.print("Enter the car number given above ");
int waitingCarNum;
waitingCarNum=in.nextInt();

if((list2.size()+11)==waitingCarNum)
{
for(int i=0;i<list2.size()-1;i++){
vehicle temp=list2.get(i);
System.out.println(temp.no);
}

list2.add(new vehicle(waitingCarNum));
System.out.println("Waiting List ");
for(int h=0;h<list2.size()-1;h++){
System.out.print(list2.get(h).no+" ");
}
 System.out.println("");


}
else{
System.out.println("Please enter correct car number ");
}
/*vehicle ghg=list2.getFirst();
if((list2.size()+11)==waitingCarNum){
list2.add(new vehicle(waitingCarNum));
System.out.println( "add to waiting list "+waitingCarNum);
System.out.println("New waiting list"+list2);
System.out.println("Thank you.Please wait...");
}
else{
System.out.println("Sir.Please enter correct car number ");
}*/

break;



case 2:
System.out.println("Thank you");
break;

}
break;


}
break;



case 2:
System.out.println("1.Depart from main garage\n2.Depart From Waiting List");
int inputNum3=in.nextInt();

try{
switch(inputNum3) {
case 1:
if(list1.size()==0){
System.out.println("Garage is empty. If you wish you can Enter your car now");
}
else{
System.out.println("Car numbers in the Car park.Choose yours ");
vehicle qsa=null;
int ssd=0;
for(int h=0;h<list1.size();h++ ){
qsa=list1.get(h);
ssd=qsa.no;
System.out.println("in Park "+ssd);
}

System.out.println("Enter the number of your car");
int RemoveCar=0;
RemoveCar = in.nextInt();
//System.out.println("");

//System.out.println("");
//vehicle qa=null;
//vehicle qa=list1.getFirst();
int sd=0;

int which=RemoveCar;// wanted car
//int =list1.peek().no;//mulma id eka

//try{
for(int h=0;h<list1.size();h++){
vehicle qa=list1.get(h);
if(qa.no!=which){
qa=list1.get(h);
continue;
}

else{
vehicle kl=null;
for(int u=0;u<list1.size()-1;u++){
kl=list1.get(u);
if(kl.no!=which){
//kl.incmoves(2);
kl.mvs+=2;
}
else
break;
}
for(int v=list1.size();(list1.get(h).no!=which);v--){
//kl.incmoves(1);
kl.mvs+=1;
}
System.out.println("moves "+ list1.get(h).incmoves(1));
list1.remove(h);
break;
}






/*qa=list1.get(h);
sd=qa.no;
System.out.println("Park now "+sd);
*/

}

//}
//catch(Exception e){
// System.out.println(e);
//}


if(list2.size()>0){
System.out.println("So car number "+list2.getFirst()+"  to car park:");
 
////////////////////////////// list1.add(list2.getFirst());

list1.add(new vehicle(list2.getFirst().no));
list2.remove(0);

System.out.println("New car list in car park : " + list1);
System.out.println("");
}
else{
System.out.println("No cars in waiting list to enter garage");
}

}break;

case 2: if(list2.size()==0){
System.out.println("There is no cars waiting in the list");
}
else{
System.out.println("Cars in waiting list"+list2);
System.out.print("Enter your car number");
int removeWaitCar=in.nextInt();
}
break;
}
}
catch(Exception e){
System.out.println("You have entered wrong Index number.please check");
}
break;
             
 



case 3:
System.out.println("What do you want to see?" );

System.out.println("1.Main garage\n2.Waiting list");
int displayNum=in.nextInt();
try{
switch(displayNum){
case 1:
vehicle carID1=null;
int carList1=0;

for(int h=0;h<list1.size();h++){
carID1=list1.get(h);
carList1=carID1.no;
System.out.println("Park now "+carList1);
}
break;
case 2:
vehicle carID2=null;
int carList2=0;

for(int h1=0;h1<list2.size();h1++){
carID2=list2.get(h1);
carList2=carID2.no;
System.out.println(carList2+" is in the Waiting list now");

}break;
//default: System.exit(0);
}
}
catch(Exception e){
System.out.println("You have enter wrong option number.please check again");
}
break;


case 4:
                        System.out.println("Have a nice day");


default: System.exit(0);






          }// switch
 
 }
}
catch(Exception e){
System.out.println(e+"You may have entered a wrong charactor.please check");
}

  }        
   
}  



class vehicle{ int no; int mvs; public vehicle(int abc){ no=abc; mvs=0; } public int incmoves(int x){ return (mvs+x); } }

A Simple Java program for a Car Park System (Psedocode)




PSEUDOCODE (Part 1)


Linked List Class
SETsize, inputNum1 to zero  

INITIALIZE   Instance Variables    
INITIALIZE Variables
PRINT if any car numbers in garage
WHILE (True)

PRINT Enter garage
PRINT Exit garage
PRINT Display
PRINT Exit

READ input lines from User Input


           CASE Enter garage:
                       IF (Car Size <9)
                       PRINT vacancies in garage
                       PRINT car number next to enter
                       READ input lines from the user
                       IF (Enter number is not the given number)  
                       PRINT Sorry you have entered a wrong car number.Please enter correct car number
                     
                       ELSE IF(Car size=0)  
                               IF (Waiting list>0)
                               PRINT First car can enter garage
                               ELSE
                               PRINT No cars in waiting list
                     
                       ELSE
                       PRINT Sorry!!!No Space. Wait at the Waiting List    
                       WHILE (True)                                                
                       PRINT would you like to add to waiting list
                       PRINT Yes                                                          
                       PRINT No                                                            
                       READ input lines from the user

                     
                CASE Yes:
                READ input Car Number from the user
                ADD to list2
                RETURN main menu
               
                CASE No:
                 RETURN main menu
     
                  CASE Exit From garage:
                  PRINT main garage
                  PRINT Waiting List
               
                       READ input lines from User Input

                               CASE main garage
                               IF(SIZE<O)
                               PRINT no cars
                               ELSE
                               PRINT State the car number
                               REMOVE
                               PRINT moves;
                               RETURN main menu


                               CASE Waiting list
                               IF(SIZE<O)
                               PRINT no cars in Waiting list
                               ELSE
                               PRINT State the car number
                               REMOVE
                               RETURN main menu
                               END CASE
               CASE Display:
               PRINT Main garage
               PRINT Waiting List
               READ input Car Number from the user
             
                       CASE Main garage:
                       PRINT car number
                       REMOVE
                       RERURN Main menu
                     
                       CASE Waiting List
                       PRINT car number
                       REMOVE
                       RERURN Main menu
                       END CASE

CASE Exit: Exit from the application
END WHILE
END Main







Friday, September 21, 2012

සිතූ පැතූ දේ ලබාගැනීමට ඉතා සරල පොඩි අභ්‍යාසයක්







මේක පොඩි සරල අභ්‍යාසයක්. කිසිම පාඩුවක් නෑ අත් හදා බැලුවට,මොකෝ වාසිය වෙන කාටවත් නෙවෙයි තමන්ටමයි. හිතේ බලේ වෙන මොන බලේටත් වඩා වැඩී කියලා අහල ඇතිනේ.අපි අර හිත ඇත්නම් පත කුඩාද කියලා කියන්නෙ සිංහලෙන්.ඉතින් ඔය නිකන් විකාර හිත හිත ඉන්න හිතෙන් තමුන්ට වෙන්න උවමනා වැඩ,ආසාවල් ඉෂ්ඨ කරගන්න පොඩී දෙයක් මේ කියන්නේ.අපි අද හිතන දේ අනාගතේ ඇත්තක්,යථාර්තයක් කරගන්න පුළුවන් විදියක්.මේ ක්‍රමේ චිත්ත රූප විද්‍යාවේ එන ක්‍රමයක්.නම් ගම් කියලා වැඩේ සංකීර්ණ කරගන්න ඕන නෑනේ,ඒ නිසා කරන වැඩේ කියන්නම්.මේ කරන වැඩේ සිතූ පැතූ දේ ඉල්ලලා එක එක්කෙනාට කන්නලව් කරනවට වඩා ලේසියි,පහසුයි,ප්‍රායෝගිකයි.

මෙන්න මෙහෙම හිතමු,තමන්ට ඕන කරන දෙයක් ලබා ගන්න ආසාවක් තියෙනවා කියලා,අන්න ඒ දේ හිතේ අධිෂ්ඨානයෙන් ලබා ගන්න විදියක් තමා මේ කියලා දෙන්න යන්නේ.කැමතිනම් කරලා බලන්න.

මේ වැඩේ කරන්න සුදුසුම වෙලාවල් විදියට මමනම් දකින්නේ එක්කෝ රෑ නින්දට යන්න කලින්,නැත්නම් උදේ නැගිට්ට ගමන්.හැබැයි උදේ නැගිට්ට ගමන් තමයි හොඳම.ඒ නැත්තත් තමුන්ට පහසු වෙලාවක් යොදාගන්න,ඒකේ ගැටළුවක් නෑ.ප්‍රධානම දේ තමා පුලුවන් තරම් හිත එකඟ කර ගැනීම.පියවරෙන් පියවර බලමු,පොඩි වැඩක් තියෙන්නේ.

1) මුලින් හිත එකඟ කරගන්න.මොකක් හරි භාවනාවක් කරන්න මිනිත්තු කීපයක්,ඒ බැරිනම් 100 ඉදන් 1 ගණන් කරන්න සිහි බුද්ධියෙන්,ආනාපානා සති භාවනාව මේකට බොහොම හොඳට ගැළපෙන බව කියන්න ඕන.

2)ඊට පස්සෙ තමුන්ගෙ ඉස්සරහින් කණ්ණාඩියක් මවා ගන්න.අඳුරු පාට කණ්ණාඩියක්.ඒකේ ඔහේ නිකන් හිතෙන් ඇඳන් යන්න තමාට වෙන්න ඕන නැති දේ.ඊට පස්සෙ ටිකකින් ඒ කණ්ණාඩිය කැඩිලා බිඳිලා සුණු විසුණු වෙලා යනවා දකින්න.

3).ඊළඟට දකින්න බොහොම දීප්තිමත් රාමුවක් තීන කණ්ණාඩියක්,අන්න ඒකේ අදින්න තමාට වෙන්න ඕන දේ.හිතන්න තමුන්ට ගෙයක් ගන්න උවමනාවක් තියෙන්නේ කියලා.එහෙනම් ගෙයක් මනසෙන් අදින්න.පුළුවාන් තරම් විස්තර ඇතුව.ඒ කියන්නේ තමුන්ට ඕන තනි තට්ටුවේ ගෙයක්ද,තට්ටු දෙකේ ගෙයක්ද,කොච්චර ලොකු වෙන්න ඕනෙද ඒ වගේ ඒවා. ගාලා තීන පාට,ගෙට ඇතුල් වෙනකොට විදිය,ඇතුල් වෙනකොට පේන දේවල,ගේ වටේ වවලා තීන මල්,ඒ මල් වල පාට වගේ හැකිතාක් විස්තර හිතෙන් ඔය කණ්ණාඩියේ අදින්න.ඊට පස්සෙ ඔය ඇඳපු චිත්‍රේ දිහා හිතෙන් බලන් ඉන්න.

ඕක දිනපතා ප්‍රගුණ කරන්න,වැඩි දවසක් යන්න කලින් තමුන්ව පුදුමයට පත් වෙන්න හිතපු වැඩේ වේවී.නිකන් කරල බලන එකනේ.

මෙහෙමයි,මේ යටි හිතෙන් වැඩ ගන්න පොඩි විදියක්. අපේ උඩු හිතයි යටි හිතයි කියලා 2ක් තීනවනේ.උඩු හිත තමා දැන් මේ වෙලාවේ තියෙන්නේ,අපි ඇහැරන් ඉන්න වෙලාවේ.නිදාගන්න ගියාම තමා යටි හිත වැඩ කරන්නේ.නැගිටලා ඉන්න මේ වෙලාවේ අපේ මනස තියෙන්නේ බීටා මට්ටමේ,නිදා ගන්නකොට ඇල්ෆා මට්ටමට එනවා.ඉතින් ඇල්ෆා මට්ටමට ගන්න නිදා ගන්නම ඕන නෑ,භාවනාවකින් වගේ හිත එකඟ උනාම මනස නිකන්ම ඇල්ෆා මට්ටමට වැටෙනවා.අන්න ඒ වෙලාට අපිට ඕන දේ යටි හිතෙන් ඉල්ල ගන්න පුලුවන්.

සමහර වෙලාට අත්දැකීම් ඇති අනේ මට මෙහෙම දෙයක් අරහෙම දෙයක් තිබ්බොත් හොඳයි කියලා හිතිලා,වැඩි දවසක් යන්න කලින් ඒ දේ තමුන් අතටම ලැබෙන. ආන්න එහෙම දෙයක් තමා මෙතනදිත් කරන්නේ.එතනදිත් වෙන්නේ තමන්ට ඕන දේ ගැන යටි හිතට පොඩි සිග්නල් එකක් දෙන එක.ආසාව වැඩි නිසා හැම වෙලේම ඕක කල්පනා කර කර හිටියම ඕක යටි හිතට සාන්ද්‍රණව වෙනවා.ඊට පස්සෙ ඉතිරිය යටි හිත බලා ගන්නවා. කැමතිනම් කරල බලන්න,බොහොම පොඩි වැඩක්!




Saturday, September 15, 2012

Learning Disabilities



What is Learning Disability?

Learning  disabilities  are  problems that affect the brain's ability to receive, process, analyze or store information. These problems can make it difficult for a student to learn as quickly as someoe who isn't affected by learning disabilities. There are many kinds of learning disabilities. Most students affect by them having more than one kind. Certain kinds of learning disabilities can interfere person's ability to concentrate or focus and can cause someone's mind to wander too much. Other learning disabilities can make it difficult for a student to read, write, spell or solve math problems.

What are the signs of learning disability?

Learning  Disabilities  are  not  noticeable  like  paralysis  or  blindness, (LD) is  a  hidden  handicap.A  learning  disability  doesn’t  leave  any  signs  behind  like  a  disfiguration,so  people  do  not  understand  or  offer  their  support.  The  different  types  of  learning  disabilities  can  be  divided  in  to  three  large  categories,Development speech and language disorders, academic skills  disorders  and  attention  disorders.Learning  disorders  affect  how  a  person  understands, remembers  and  responds to new  information.People with learning disorders may have problems.
  • Listening  or  paying  attention
  • Speaking
  • Reading  or  writing
  • Doing  math

           What are the speech and Language problems?


Developmental  speech  and  language  disorders  are  of  speech  and  language  problems,  most  often  the  earliest  signs  are  of  a  learning  disability.Those  with  this  handicap  have  a  tough  time  producing  speech  sounds,  using  speech  language  to  communicate  and understand what others are trying to get across (“People with developmental speech and language disorders have difficulty producing speech sounds, using spoken language to communicate, or understanding  what  other  people  say”) Depending  on  the  difficulty  a  person  might  be  having,  their  diagnosis  may  be  one  of  the  following  developmental  articulation  disorder,  developmental  expressive  language  disorder  and  developmental  receptive  language  disorder. When  children  have  developmental  articulation  disorder  they  may  have  trouble  controlling  the  pace  in  which  they  speck.  Also  they  tend  to  stay  behind  their  classmates  in  learning  to  make  speech(like “wabbit  instead  of  “rabbit”  and  “thwim”  for  “swim”) This  disorder  is  found  in  at  least  10  percent  of  children  under  the  age  of  8.  But  good  news  articulation  disorder  can  be  out  grown  or   it  can  be  departed  with  speech  therapy.

Children  who  have  developmental  expressive  language  disorder  have  difficulties  expressing  themselves  in  their  dialogue  for  example  a  child  might  call  objects  by  their  incorrect  names (for  example   calls  objects  by  the  wrong  names ) This  disorder  can  take  other  forms  like  if  a  child  only  specks  in  two  word  sentences,  also  if  they  seem  to  have  trouble  answering  simple  questions.  Some  people  have  problems  with  different  areas  of  speech,  further  more  this  disorder  is  called  developmental  receptive  language  disorder.  This  disorder  can  make  someone  seem  slow  because  they  can’t  understand  or  do  a  simple  task ( The  toddlers  who  don’t  respond  to  their names,  a  preschooler  who  hands  you  a  bell  when  you  ask  him  for  a  ball,  or  the  worker  who  consistently  can’t  fallow  simple  directions”)

Who suffer more with learning disorder?
Individuals who suffer with academic skills disorder are often students.  They  are  years  behind  in  their  development  of  understanding  reading,  writing  and  arithmetic  skills.  The  anguish  student  can  be  diagnosed  with  developmental  reading  disorder,  developmental  writing  disorder  or  developmental  arithmetic  disorder.  Starting  with  developmental  reading  disorder,  this  is  also  known  as  dyslexia.  Surprising  2  out  of  8  percent  of  elementary  school  children  are  affected  by  this  disorder.  Remember  to  read  you  must  focus  your  attention  on  the  printed  words and control eye movements across the page, recognized the sounds of letters, understand words and grammar, create ideas and images, evaluate new ideas to what you already recognize and store ideas in memory. All of that requires an interactive network of brain cells which are in charge of vision, language and memory. Scientists have found that people with dyslexia have problems differencing the sounds in verbal sounds (“However scientists found that a significant number of people with dyslexia share an inability to distinguish or separate the sounds in spoken words”) Though if the brain is incapable to shape images when reading or to relate new thoughts to those stored in memory, the reader will not recognize and even keep in mind the new concepts.

An attention disorder affects 20 percent of school children. This disorder enables them to focus their attention. This disorder makes people daydream, and when you do get their attention they often are distracted easily. Boys are more affected by this disorder. This problem can be escorted by hyperactivity, this disorder can go with them in to their adulthood; this can make them restless and in their work seem not to follow directions, finish work and not well organized.

Although learning disorders occur in very young children, they are usually not recognized until the child reaches school age. About one-third of children who have learning disabilities also have Attention Deficit Hyperactivity Disorder (ADHD for short.), which makes it hard to focus.

What are the Characteristics of ADHD?

ADHD is more common in boys than girls, and it affects 3-5 percent of children in the United States. The principal characteristics of ADHD are
  • Inattention
  • Hyperactivity
  • Impulsivity
No one knows exactly what causes ADHD. It runs in families, so genetics may be a factor. A complete evaluation by a trained professional is the only way to know for sure if your child has ADHD. Treatment often includes medicines to control symptoms. Structure at home and at school is also important. Parenting classes or behavioral therapy may also help.

Evaluation and testing by a trained professional can help identify a learning disorder. The next step is special education, which involves helping your child in the areas where he or she needs the most help. Sometimes tutors or speech or language therapists also work with the children. Learning disorders do not go away, but strategies to work around them can make them less of a problem.

What are the reasons for learning disorder?

Scientists believe that learning disabilities can be caused by the intake of drugs by an expecting mother. The fetus brain my not form properly. Also an error during a woman’s pregnancy, this is that the neurons may be changed or how they interconnect. LD can also be genetic. If someone in your family has or had a learning disability (it can be your mother/father) you might have been born with it. Learning Disabilities can be life-long conditions that, in some cases affect many parts of a person’s everyday routines like school, work, and family life and sometimes with their friendships and play. Sometimes if the person is fortunate a signal learning problem has little impact on other areas of their lives. Learning disabilities cannot be diagnosed like some other illnesses which have predictable symptoms. LD can show up in so many forms, it’s difficult to diagnose and pinpoint the causes. Therefore no such pill exists nor remedy that will eliminate the problem.

What are the treatments for learning disorders?

The most common treatment for learning disabilities is special education. Specially trained educators may perform a diagnostic educational evaluation assessing the child's academic and intellectual potential and level of academic performance. Once the evaluation is complete, the basic approach is to teach learning skills by building on the child's abilities and strengths while correcting and compensating for disabilities and weaknesses. Other professionals such as speech and language therapists also may be involved. Some medications may be effective in helping the child learn by enhancing attention and concentration. Psychological therapies may also be used.


References

· Diana Hacker (Boston: Bedford/St. Martin’s, 2006).: Sample APA Formatted Paper:website:http://dacc.nmsu.edu/library/Research/Hacker-Sample%20APA%20Formatted%20Paper.pdf
·         Rayner, K., Foorman, B. R., Perfetti, C. A., Pesetsky, D., & Seidenberg M. S. (2001). How psychological science informs the teaching of reading. Psychological Science.
·         Research Paper Format Example: web site:
http://www.professays.com/research-papers/popular-research-paper-topics-2/
    ·         Fletcher, J.M., Fuchs, L.S., Barnes, M.A. (2007).  Learning Disabilities:  From Identification to Intervention. New York, NY: Guilford Press

Friday, September 14, 2012

Simple Java program for Rabin-Karp Algorithm


class rabinKarp{
public static void main(String[] args){
String txt="abcdefghijhsfdjghdsfjhgjkfdsfghk"; //test data
String ptn="fgh";
int n=txt.length();//get the lenght of the given text
int m=ptn.length();//get the lenght of the pattern given
int hashOfPatt= ptn.hashCode(); //get the hash value of the pattern

/*a loop runs shorter than the text lenght to find out the hashes tally each other*/
for(int i=0;i<n;i++){
if(i+m+1<=n){
String sub=txt.substring(i,i+m);//split the text consecutively by lenght of the pattern

int hashOfSub=sub.hashCode(); //check hash of the text and hash of the pattern match each other


if(hashOfPatt==hashOfSub){ //if the pattern and text tallies, then start character by character checking

int k=0;
boolean d=true;

/*loop runs through both the selected parts to check whether both the parts match each other*/

for(int j=i;j<i+m;j++){ 
if(txt.charAt(j)==ptn.charAt(k)){ 
k++;
}
else{
d=false;
break; //end ot loop when a un matchable part found
}
}
if(d){
System.out.println(sub); //print the pattern each and every time a match found
}
}
}
}
}
}