Permutation Project

Discussion in 'Programming General' started by jo3s, Dec 22, 2010.

Permutation Project
  1. Unread #1 - Dec 22, 2010 at 7:13 PM
  2. jo3s
    Joined:
    Aug 15, 2010
    Posts:
    407
    Referrals:
    0
    Sythe Gold:
    0

    jo3s Forum Addict
    Banned

    Permutation Project

    Write a Java project that produces random permutations of the numbers 1 to 10. To generate a random permutation, you need to fill an array with the numbers 1 to 10 so that no two entries of the array have the same contents. You could do this by brute force, by calling Math.random() until it produces a value that is not yet in the array. An alternative would be to create a second array and fill it with the numbers 1 to 10. Pick one of those numbers at random, remove it from the array, and append it to the permutation array.

    In developing this project, you should create a class called PermutationGenerator. It should have one instance field, an integer array called permutation. It should have a default constructor that constructs the permutation array with 10 memory addresses (if you did not do this when you declared it as an instance field) and calls a mutator method setPermutation() which will fill the array. This class also needs an accessor method getPermutation().

    This project also requires a driver class. This driver should print to the console window 10 permutations of the numbers 1 to 10. The output should look something like this:

    4 6 10 7 8 3 9 5 2 1

    5 4 7 2 8 10 1 6 9 3

    1 4 3 5 8 7 6 2 10 9

    3 10 2 8 1 4 5 6 9 7

    6 1 9 5 3 10 7 4 8 2

    3 1 10 8 5 4 6 2 7 9

    7 8 2 6 1 3 10 4 9 5

    6 9 5 7 4 2 1 3 10 8

    5 6 8 1 2 9 4 10 7 3

    7 6 8 2 3 5 9 4 10 1

    To produce this output, you will have to construct an object of type PermutationGenerator inside a for loop, use this object to call the accessor method, and print the contents of the returned array. Use the enhanced for loop to print the contents of each array.


    To submit your solution for credit, follow the instructions on the assignments page. Be sure to include a picture of your output and your code. If you finish early, feel free to help other students in the lab complete their assignment.


    All help appreciated
     
  3. Unread #2 - Dec 23, 2010 at 12:44 PM
  4. Pottworth
    Joined:
    Nov 27, 2005
    Posts:
    83
    Referrals:
    0
    Sythe Gold:
    0

    Pottworth Member

    Permutation Project

    Do you need help with any particular part?
     
  5. Unread #3 - Dec 23, 2010 at 2:27 PM
  6. jo3s
    Joined:
    Aug 15, 2010
    Posts:
    407
    Referrals:
    0
    Sythe Gold:
    0

    jo3s Forum Addict
    Banned

    Permutation Project

    I'm just confused overall :(
     
  7. Unread #4 - Dec 23, 2010 at 4:18 PM
  8. Pottworth
    Joined:
    Nov 27, 2005
    Posts:
    83
    Referrals:
    0
    Sythe Gold:
    0

    Pottworth Member

    Permutation Project

    Well this is how I'd start it (Providing you are stuck on arrays!)

    Make the PermutationGenerator class

    Make an instance variable "currentIndex"
    Make the array
    *private int[] array;*

    Constructor
    Set the currentIndex to 0
    array = new array[10];


    setPermutation() method
    *{
    array[currentIndex] = new array(Math.random(), ....*10 spaces*...., Math.random() );
    currentIndex++;
    }*


    I don't know if this will be any help, you weren't specific enough with what you were stuck on.
     
< How do i use anchor code in sythe | Need help editing something >

Users viewing this thread
1 guest


 
 
Adblock breaks this site