Josephus Flavius Problem Help Please

T

TheGodfather

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!!??
 
S

Steve Wampler

TheGodfather said:
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
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

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.
 
J

John W. Kennedy

TheGodfather said:
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.

--
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"
 
T

TheGodfather

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
 
J

John W. Kennedy

TheGodfather said:
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.
--
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"
 
L

Lew

TheGodfather said:
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

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.
 
S

Steve Wampler

Roedy said:
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.
 
R

RedGrittyBrick

TheGodfather said:
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

http://www.catb.org/~esr/faqs/smart-questions.html#not_losing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top