Reference no: EM13944987
Write a program 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 it by brute force, by calling Random.nextInt until it produces a value that is not yet in the array. Instead, you should implement a smart method. Make a second array and fill it with the numbers 1 to 10. Then pick one of those at random, remove it, and append it to the permutation array. Repeat 10 times. Implement a class PermutationGenerator with a method
int[] nextPermutation
Use the following class as your main class:
/**
This class prints 5 permutations of the numbers 1 through 10.
*/
public class PermutationPrinter
{
public static void main(String[] args)
{
PermutationGenerator gen = new PermutationGenerator(10);
for (int i = 1; i <= 5; i++)
{
for (int n : gen.nextPermutation())
System.out.print(" " + n);
System.out.println();
}
}
}
Complete the following class in your solution:
import java.util.Random;
/**
This class generates permutations of a sequence of integers
1...length.
*/
public class PermutationGenerator
{
. . .
/**
Construct a PermutationGenerator object.
@param length the length of the permutations generated
by this generator.
*/
public PermutationGenerator(int length)
{
. . .
}
/**
Gets the next permutation.
@return the array containing the next permutation
*/
public int[] nextPermutation()
{
. . .
}
}
The length of the wire segment ab
: 1. In th ediagram below, wire segment AB is horizontal. The radius of loop is 6.00 inches. What is the length of the wire segment AB?
|
What is collateral on a loan that remains in the possession
: What is collateral on a loan that remains in the possession of the borrower and not the bank?
|
Difference in payments
: You buy a car today for $29,000. If you finance it with a 6% APR, 4 year loan, what is the difference in your payments if you agree to pay at the beginning of each month rather than at the end? Assume monthly compounding.
|
Discuss the rights and liabilities of the partners and lemon
: Sophia and Ben did not know about this order until the films were delivered at their shop, with a bill for $8,000.00. Sophia and Ben were furious on learning of this transaction and contacted Lemon International Ltd to pick these goods from their par..
|
Program that produces random permutations of the no 1 to 10
: Write a program that produces random permutations of the numbers 1 to 10.
|
Average collection period and the average payment period
: You know the following. ATO, ITO and FATO are 2, 6, and 2.5 respectively while for the industry they are 4.4, 19 and 4 respectively. The current ratio and quick ratio are 1 and 1.5 for the firm and 2.3 and 2.0 for the industry respectively. Net profi..
|
Discuss the research method needed to test
: You can make suggestions for research hypotheses and discuss the research method needed to test them.
|
Preferred stock which pays-cops drops
: We have a preferred stock which pays $ 8 per year. When we buy it, the cops is 8% .We keep it for 2 years and then sell it. At that time, cops drops to 4%. What is the price we sell it at? If the stock is called after 4 years at 120%, if the cops is ..
|
Average braking distance for a small car
: It is advertised that the average braking distance for a small car traveling at 65 miles per hour is less than 120 feet. A transportation researcher wants to determine if the statement made in the advertisement is false. She randomly test drives 3..
|