Closed Thread
Results 1 to 2 of 2

Thread: Help anyone pls!! Java program

  1. #1
    DexterHol is offline Newbie
    Join Date
    Nov 2007
    Posts
    1
    Rep Power
    0

    Help anyone pls!! Java program

    Hello! I'm from greece and I'm new to using java. I have the following project to deliver tomorrow and I need some help if anyone can help me pls... The project is the following:
    We are in the middle ages and we have a round table and M knights (1,2,3,4,...,m). Each time we have to send one knight to a mission. We need to pick one randomly, so we pick a random number k and start counting from knight 1 till we reach knight k. Thid knight k is excluded from the mission. Then we keep counting starting from the next knight (k+1) and we count till k again and the next knight we find is excluded again. If we reach the final knight (knight m) we start over again and we keep excluding knights till we remain with one, which is the knight to execute the mission. For example:
    If M=5 and k=2
    1,2,3,4,5 -> knight 2 is excluded -> 1,3,4,5 -> knight 4 is excluded -> 1,3,5 -> knight 1 is excluded -> 3,5 -> knight 5 is excluded -> knight 3 should execute the mission!
    So we need a function S(m,k) which will return the remaining knight given the numbers m,k. I should write now a java program that fills and returns a 2d table A[m,k]=S20x20 where A[m,k]=S(m,k).
    I have to use classes, programm flow check structures and methods on the functions for each calculation and action. Also I have to put in comments at the start of each class which explains what each class is doing...
    Practically the program will just give out a 20x20 table.

    I know this is an easy thing to do, but I can;t do it cause I don;t have any experience with java. If anyone could help I would be grateful. My e-mail and msn is basilism21@hotmail.com
    Thanks a lot for your time....

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    You need to use the rand() class to generate a random integer, and use an array list to store M knights. In the S(m, k) method loop it m-1 times, and delete the array list index each time. Once the loop is done, only one knight will be left and thats the one who goes on the mission.

    Good luck

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Upload Java program
    By Escape in forum HTML Programming
    Replies: 2
    Last Post: 03-06-2011, 01:44 PM
  2. Help on my Java program
    By J_hollow in forum Java Help
    Replies: 2
    Last Post: 05-10-2010, 10:22 AM
  3. First and Hardest Java Program
    By Dyroxide in forum Java Help
    Replies: 4
    Last Post: 02-23-2009, 07:51 PM
  4. Need Help With Java Program
    By coala2000 in forum Java Help
    Replies: 3
    Last Post: 12-28-2008, 05:42 AM
  5. First Java Program and .....
    By Void in forum Java Help
    Replies: 1
    Last Post: 10-03-2006, 05:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts