help for josephus folks!!!

T

TheGodfather

hi every one , i am trying to solve josephus problem , well i did
indeed but when i tried to put my method inside the josephus file
instead of josephus app it all messed up and i dono now what is wrong
or how can i fix it so please if u can help i ll appreciate it

the josephus file is the following :
//**Here is the file
====================================================================
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!");

}
}

====================================================================
//**Here is the App file
====================================================================
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();
}
}
}
}

====================================================================
//**Here is the error
=====================================================================
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.
==================================================================
PLEASE anyone help ?!?!?!?!??!?!
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top