Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Josephus Flavius Problem Help Please

Thread view: 
TheGodfather - 29 Nov 2007 22:45 GMT
hey folks i did solve josephus problem to day , but when i made a
little change and i took some code from JosephusApp to josephus it is
all ruined and i dono why i ll post everything maybe u can help me ,
anybody please;
Josephus
//===================================================================
class Josephus
{
   Node first;
   Node last;
    Node ring;

    Josephus()
        {
            first = null;
            last = null;
            ring = null;
        }

   Node circle(int key)
   {
       Node first  = new Node(key);
       Node last = first;
       first.key = key;

       for (int j = key - 1; j > 0 ; j--)
       {
           Node ring  = new Node(j);
           ring.key = j;
           ring.next  = first;
           first   = ring;
       }
           last.next = first;
           return last;
   }

public void suicide()
   {
       Node reference = circle(A);
       while (reference != reference.next) //when there are still
more than 1 person
       for (int i = 1; i < B; i++)//you can still execute the B
person
       reference = reference.next;
       System.out.println( "-R.I.P # "+ reference.next.key );
       reference.next = reference.next.next;
       System.out.println();
       System.out.println("Josephus has to take position ( " +
reference.key + " ) to survive!");

    }
}
//===================================================================
JosephusApp
//===================================================================
import java.io.*;
//---------------
class JosephusApp
{
    public static void main (String[] args) throws IOException
      {
       InputStreamReader inStream = new InputStreamReader(System.in);
        BufferedReader stdin = new BufferedReader(inStream);
        Josephus Josephus = new Josephus();
        String inData;
        int A;
        int B;

        System.out.println("Welcome to 'Josephus, a smart jew' problem
solver.");
   
System.out.println("**************************************************");
          System.out.println("How Many Jews want to commit suicide
today?");
        inData = stdin.readLine();
        A =  Integer.parseInt(inData);

    if (A <=0)
       {
           System.out.println("Try a positive number!");
        }
    else
       {
           System.out.println();
            System.out.println("Eliminate one every :");
            inData = stdin.readLine();
            B =  Integer.parseInt(inData);
            System.out.println();

    if (B <=0)
       {
           System.out.println("Try a positive number!");
       }

    else
        {
            Josephus.suicide();
       }
    }
 }
}

//===================================================================
THE ERROR
//===================================================================
--------------------Configuration: JDK version 1.3
<Default>--------------------
F:\Josephus.java:35: cannot resolve symbol
symbol  : variable A
location: class Josephus
       Node reference = circle(A);
                               ^
F:\Josephus.java:37: cannot resolve symbol
symbol  : variable B
location: class Josephus
       for (int i = 1; i < B; i++)//you can still execute the B
person
                           ^
2 errors
Process completed.
//===================================================================
Can anyone help Please guyz!!??
Steve Wampler - 29 Nov 2007 23:09 GMT
> hey folks i did solve josephus problem to day , but when i made a
> little change and i took some code from JosephusApp to josephus it is
> all ruined and i dono why i ll post everything maybe u can help me ,
> anybody please;
...
> F:\Josephus.java:35: cannot resolve symbol
> symbol  : variable A
[quoted text clipped - 6 lines]
>         for (int i = 1; i < B; i++)//you can still execute the B
> person

A and B are local variables in your 'main' method in the JosephusApp
class.  They are not visible to your Josephus class.  You'll have to
find a way to transfer the values of A and B into Josephus.  One way
would be do have instance variables defined in Josephus to hold those
two values and then to pass the values in the constructor call.  This
will require you to rearrange the code in your main to call the
constructor after you've read those values in.

Signature

Steve Wampler -- swampler@noao.edu
The gods that smiled on your birth are now laughing out loud.

John W. Kennedy - 29 Nov 2007 23:32 GMT
> hey folks i did solve josephus problem to day , but when i made a
> little change and i took some code from JosephusApp to josephus it is
> all ruined and i dono why i ll post everything maybe u can help me ,
> anybody please;

A) We speak English here, not gibberish.

B) This isn't a chat room.

C) You seem to be under the impression that a method in one class can
use variables declared in another method in another class.
Unfortunately, current computer hardware does not have internal telepathy.

Signature

John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
  -- Charles Williams.  "Judgement at Chelmsford"

TheGodfather - 30 Nov 2007 00:13 GMT
who the hell you think you are?
who are you to judge me?
u felt offended with my english?
take a piece of advice , next time dont open my posts
and if you are here to be a clown youd better go to a circus
telepathy... are you moqing somebody here? or your mother gave you
birth with a PhD in comp.science in your hands
please do the world a favour and shut up
John W. Kennedy - 30 Nov 2007 01:48 GMT
> who the hell you think you are?
> who are you to judge me?
> u felt offended with my english?

Grow up, kiddy. Your teenage angst doesn't pass among adults.
Signature

John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
  -- Charles Williams.  "Judgement at Chelmsford"

Lew - 30 Nov 2007 01:53 GMT
> who the hell you think you are?
> who are you to judge me?
[quoted text clipped - 4 lines]
> birth with a PhD in comp.science in your hands
> please do the world a favour and shut up

Plonk.

U cn forgt abt gtg hlp in hr.

Take a piece of advice, and behave like a professional, not a spoiled child
ready to flame anyone who tries to help you.

Signature

Lew

Roedy Green - 30 Nov 2007 07:48 GMT
On Thu, 29 Nov 2007 16:13:24 -0800 (PST), TheGodfather
<saliba.toufic.george@gmail.com> wrote, quoted or indirectly quoted
someone who said :

>u felt offended with my english?

No.  For your refusal to use English.  see
http://mindprod.com/jgloss/textspeak.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

RedGrittyBrick - 01 Dec 2007 22:55 GMT
> who the hell you think you are?
> who are you to judge me?
[quoted text clipped - 4 lines]
> birth with a PhD in comp.science in your hands
> please do the world a favour and shut up

http://www.catb.org/~esr/faqs/smart-questions.html#not_losing
Roedy Green - 30 Nov 2007 07:47 GMT
On Thu, 29 Nov 2007 14:45:43 -0800 (PST), TheGodfather
<saliba.toufic.george@gmail.com> wrote, quoted or indirectly quoted
someone who said :

>hey folks i did solve josephus problem to day

Examining just snippets, this looks like some racist joke. What is the
Josephus problem?
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Steve Wampler - 30 Nov 2007 13:11 GMT
> On Thu, 29 Nov 2007 14:45:43 -0800 (PST), TheGodfather
> <saliba.toufic.george@gmail.com> wrote, quoted or indirectly quoted
[quoted text clipped - 4 lines]
> Examining just snippets, this looks like some racist joke. What is the
> Josephus problem?

Josephus was a famous Jewish historian, back when Rome ruled the
'known' world.  The story this is based on (uncertain if it's true,
but I doubt it) is that he was also once a Jewish military commander.
When his group became trapped by the Roman legions, they resolved
to all die rather than surrender.  The technique alluded to here
was that they selected a number N and counted around the group.
The Nth person was then killed by the others and the count restarted
with the next in line.  And so on.  Josephus positioned himself
so that he would be last, surrendered to the Romans and began
reporting on the Roman conquests.

When teaching, I used to turn this into the "Howard Hughes Will"
problem (lots of wills out there, once upon a time).  These days it
could be the "Anna Nicole Smith Will" problem...  You need to put
your versionof the will in the correct spot.

Signature

Steve Wampler -- swampler@noao.edu
The gods that smiled on your birth are now laughing out loud.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.