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 5 of 5

Thread: FLAMES GAME

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default FLAMES GAME

    public void FLAMES()
    {

    name1 = new StringBuffer(firstName.getText());
    name2 = new StringBuffer(secondName.getText());
    for (int i = 0; i < name1.length(); i++)
    {
    char ch = name1.charAt(i);
    for (int j = 0; j < name2.length(); j++)
    {
    if (ch == name2.charAt(j))
    {

    name1.deleteCharAt(i);
    name2.deleteCharAt(j);
    i = -1;
    break;
    }

    }

    }


    int totallength = name1.length() + name2.length();


    StringBuffer str = new StringBuffer("FLAMES");
    int cancel_value = 1;

    for (int i = 0; i < 5; i++)
    {
    cancel_value = totallength % str.length();

    if (cancel_value == 0)
    {
    cancel_value = str.length();
    }
    cancel_value--;

    if (cancel_value == 0)
    {

    str = new StringBuffer(str.substring(1));
    } else if (cancel_value == (str.length() - 1))
    {

    str = new StringBuffer(str.substring(0, str.length() - 1));
    } else
    str = new StringBuffer(str.substring(cancel_value + 1)
    + str.substring(0, cancel_value));

    }

    just.setVisible(true);
    Output.setText(relation(str.charAt(0)));


    }


    I GOT A LITTLE CONFUSE HERE.. IN A SCRATCH PAPER I TRY TO SOLVE A COUPLE'S NAME
    WHICH IS THE FIRST NAME IS "JEROME PAMPOSA" AND THE 2ND ONE IS "JOAN VILLAR"
    IN MY PROGRAM.. THE RESULT OF THE COUPLE IS "A" which means "AFFECTION" but in my
    SCRATCH PAPER.. THE RESULT IS "E" which means "ENEMY".. so.. im very confuse why is my program
    not match in my scratch result.. i search many sites but the codes was the same.. but if u will do
    the flames game in a paper.. its different between the program and the manual procedure..


    can anyone help me? thanks in advance


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: FLAMES GAME

    Put some System.out.println()s in your for loops that print out the values of the loop indexes (i and j) and also the contents of the StringBuffers name1 and name2 so that you can see how they change while your code is running

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

    Red face Re: FLAMES GAME

    Quote Originally Posted by arben View Post
    public void FLAMES()
    {

    name1 = new StringBuffer(firstName.getText());
    name2 = new StringBuffer(secondName.getText());
    for (int i = 0; i < name1.length(); i++)
    {
    char ch = name1.charAt(i);
    for (int j = 0; j < name2.length(); j++)
    {
    if (ch == name2.charAt(j))
    {

    name1.deleteCharAt(i);
    name2.deleteCharAt(j);
    i = -1;
    break;
    }

    }

    }


    int totallength = name1.length() + name2.length();


    StringBuffer str = new StringBuffer("FLAMES");
    int cancel_value = 1;

    for (int i = 0; i < 5; i++)
    {
    cancel_value = totallength % str.length();

    if (cancel_value == 0)
    {
    cancel_value = str.length();
    }
    cancel_value--;

    if (cancel_value == 0)
    {

    str = new StringBuffer(str.substring(1));
    } else if (cancel_value == (str.length() - 1))
    {

    str = new StringBuffer(str.substring(0, str.length() - 1));
    } else
    str = new StringBuffer(str.substring(cancel_value + 1)
    + str.substring(0, cancel_value));

    }

    just.setVisible(true);
    Output.setText(relation(str.charAt(0)));


    }


    I GOT A LITTLE CONFUSE HERE.. IN A SCRATCH PAPER I TRY TO SOLVE A COUPLE'S NAME
    WHICH IS THE FIRST NAME IS "JEROME PAMPOSA" AND THE 2ND ONE IS "JOAN VILLAR"
    IN MY PROGRAM.. THE RESULT OF THE COUPLE IS "A" which means "AFFECTION" but in my
    SCRATCH PAPER.. THE RESULT IS "E" which means "ENEMY".. so.. im very confuse why is my program
    not match in my scratch result.. i search many sites but the codes was the same.. but if u will do
    the flames game in a paper.. its different between the program and the manual procedure..


    can anyone help me? thanks in advance

    just use if(C == 3 || C == 5){
    System.out.println(nme+" and "+lnme+" are good FRIENDS\n");
    }
    Refer this website,i hope its useful
    ...
    Last edited by copeg; September 9th, 2012 at 01:20 PM. Reason: removed external link

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: FLAMES GAME

    Please don't resurrect a year old post, especially to post external links. Doing so will often make you look like you are posting solely to promote a website - which is considered spam.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FLAMES GAME

    you have to check that you are cutting the alphabet where it stops or the first ones .

Similar Threads

  1. Need Help with Game
    By Shivam24 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 18th, 2011, 03:58 PM
  2. Game
    By aneeeeen in forum Paid Java Projects
    Replies: 2
    Last Post: April 16th, 2011, 08:32 AM
  3. Help me with My Game.
    By jtvd78 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 13th, 2011, 04:14 PM
  4. Game !
    By Ahmed.Ibrahem in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2011, 08:01 PM
  5. Game 3x3
    By Koren3 in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 20th, 2009, 08:43 PM