Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Markov model

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Markov model

    Hi im really finding it hard to see what is wrong with my code. any help would be greatly appreciated.
    It is for this project : project_3 - RW 144



    import org.w3c.dom.Node;
    public class LinkedList
    {
    private Node first;
    Node last;
    private class Node
    {
    Node next;
    String Kgram;
    int[] asci = new int[127];
    int count =0;
    }


    LinkedList() // default constructor
    {
    first = new Node() ;
    }
    LinkedList(LinkedList l) // copy constructor
    {
    first = l.first;
    }

    private void check(String current,Node last )
    {
    char cchar = current.toString().charAt(0);
    int iaski = ((int)cchar);

    last.asci[iaski]++;

    }

    public void add(String kgram) // adds a kgram to the linked list if it already exists then it increments its count
    {

    String silly;
    if (first.Kgram == null)
    {
    System.out.println("first added");
    System.out.println(kgram);
    first.Kgram = kgram;
    last = first;
    return;
    }
    for(Node x=first ;x != null;x=x.next)
    {
    silly = x.Kgram.toString();
    if(silly.equals(kgram))
    {

    System.out.println("double");
    System.out.println(kgram);
    x.count++;
    check(kgram, last);
    last = x;
    return;
    }

    if(x.next ==null)
    {

    System.out.println("single");
    System.out.println(kgram);
    Node newnode = new Node();
    newnode.Kgram = kgram;
    x.next = newnode;

    check(kgram, x);
    last = x.next;
    }
    }
    }

    void printList() // prints all the item of the list in order
    {
    char c ;
    for(Node x = first; x!= null;x = x.next )
    {
    System.out.print(x.Kgram) ;
    for(int i=0;i<127;i++)
    {
    if(x.asci[i]>0)
    {
    c = (char) i;
    System.out.print("" + c + "" + x.asci[i]);
    }
    }
    System.out.println();
    }

    }

    public static void main(String [] args)
    {
    LinkedList l = new LinkedList();
    l.add("aa");
    l.add("ag");
    l.add("ad");
    l.add("ae");
    l.add("af");



    l.printList();



    }

    }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Markov model

    Quote Originally Posted by KobusJordaan View Post
    Hi im really finding it hard to see what is wrong with my code. any help would be greatly appreciated.
    It is for this project : project_3 - RW 144
    You may wish to provide more information to allow us to be better able to help you, information such as what exactly is the program supposed to be doing (don't use a link for this, please put the effort in to post it in with your question -- we're volunteers after all), what errors if any are you seeing, how your program is misbehaving, etc...
    Last edited by curmudgeon; October 19th, 2012 at 09:15 PM.

Similar Threads

  1. Database link tables to model
    By niekname in forum Object Oriented Programming
    Replies: 1
    Last Post: May 17th, 2012, 09:51 PM
  2. Killing view of a dead model
    By Alice in forum Java Theory & Questions
    Replies: 9
    Last Post: May 30th, 2011, 05:27 AM
  3. creating table model....
    By kollyisrealisaac in forum Java Theory & Questions
    Replies: 1
    Last Post: May 6th, 2011, 09:07 AM
  4. Unstructured Data Model
    By richip in forum Object Oriented Programming
    Replies: 1
    Last Post: March 17th, 2011, 09:25 AM
  5. the problems of psx model ripping
    By wolfgar in forum Java Theory & Questions
    Replies: 4
    Last Post: November 4th, 2009, 07:31 PM

Tags for this Thread