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

Thread: Create non repeated words

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Create non repeated words

    Hello guys,
    I wrote a code for a "skydiving" program that randomly selects the "maneuvers" to be performed by the skydiver during his skydive. I am almost done with the program. I just need to figure out how to print non repeated maneuvers for each round. Each round may not consist of two of the same maneuvers. The program that I wrote randomly picks the maneuvers but sometimes it still prints out two of the same maneuvers for each round. I have no clue how to do this. Any ideas? Thank you very much in advance.

    The following is my code.


     
    import java.util.Scanner;
    import java.util.Random;
    ///v.0
    public class Testpart2 {
     
     
     
    	public static void main(String[] args) {
    		Random randomNumbers=new Random();
    		Scanner input = new Scanner(System.in);
    		// TODO Auto-generated method stub
     
    	int A;
    	int count;
    	int roundcount;
    	roundcount=0;
     
     
    String wordA = "2-Sidebody-Donut or INTER or Side Flake Donut,TEST:4-Monopod or INTER TEST:6-Stardian or INTER TEST :7-Sidebuddies or INTER TEST:9-Cat-Accordian or INTER TEST:15-Caterpilar or INTER TEST:19-Ritz or INTER or Icepick TEST:21-Zig-Zag or INTER or Margus TEST";
    String[] wordAAsArray = wordA.split(":");/////Condition for class A
     
     
     
    System.out.println(" How many rounds would you like to produce? - Enter 6 or 10");
    count=input.nextInt();
     
    System.out.println("");
     
    System.out.println("Does your team belong to the class A, (1 for YES. 0 for NO)");/////////// A class
     
    A = input.nextInt();
     
     
     
    for (int i = 1; i <= count; i++)
    {
    	roundcount++;
    	System.out.println("-------------------------Round " +roundcount);
    	System.out.println();
    if (A==1) /////Class A
    		{
     
    	System.out.println(" Your team shold perform the following dives (A-CLASS)!");
    		System.out.println();
     
    		{int index = new Random().nextInt(wordAAsArray.length);
    		String random1Word = wordAAsArray[index];
    		System.out.println("Dive #1 -A = " +random1Word);}
     
    		{int index = new Random().nextInt(wordAAsArray.length);
    		String random1Word = wordAAsArray[index];
    		System.out.println("Dive #2-A = " +random1Word);}
     
    		{int index = new Random().nextInt(wordAAsArray.length);
    		String random1Word = wordAAsArray[index];
    		System.out.println("Dive #3-A = " +random1Word);
     
    		}
     
     
    		}
     
    }
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Create non repeated words

    A couple of ideas:
    Save the ones that were used in a list and check if the next one chosen is in the list.
    Put all the maneuvers in a list, shuffle the list and remove them one at a time from the beginning
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,376
    My Mood
    Mellow
    Thanks
    143
    Thanked 598 Times in 585 Posts

    Default Re: Create non repeated words

    A set of objects can be a useful way to determine if an object has already been chosen. Choose an object and add it to the set. If the set accepts the object, then that object has not been previously chosen and added to the set. If the set does not accept the object, well, you can see the rest.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Create non repeated words

    Also posted at: Create Non Repeated Words - Java | Dream.In.Code
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: February 10th, 2014, 05:24 AM
  2. Replies: 12
    Last Post: March 17th, 2013, 01:38 AM
  3. A Program that will ask five letters and create a possible words
    By jms25 in forum Java Theory & Questions
    Replies: 11
    Last Post: September 23rd, 2012, 09:40 PM
  4. finding the most repeated name in a stack
    By skoon in forum Java Theory & Questions
    Replies: 1
    Last Post: January 18th, 2012, 05:39 AM
  5. finding the most repeated name in a stack
    By skoon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 18th, 2012, 12:26 AM

Tags for this Thread