How to construct a permutationgenerator object

Assignment Help Computer Engineering
Reference no: EM1328295

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()
{
. . .
}
}

Reference no: EM1328295

Questions Cloud

How could illegal immigration problems be solved : How could illegal immigration problems be solved?
Important information regarding price elasticity : Important information regarding Price Elasticity of Demand and Total Revenue
How do you write an exponential decay function : How do you write an exponential decay function to model a situation?
Aspect of the requirement for the cross-cultural team : In this case specifically do you think the requirement of an "environmentally freely" solution might create an issue given different cultures definition and awareness of adverse environmental impact? As a leader how would you address that aspect of t..
How to construct a permutationgenerator object : note down  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 \array have the same contents.
Computer hardware industry analysis research paper : Computer hardware industry analysis research paper - need a computer hardware industry analysis including contents
Time value of money issues : You're planning the round-the-world travel extravaganza with friends, with departure date five years from today. The cost of such a trip today is $10,000, but you expect the cost in 5 years to increase at the expected rate of inflation (2%).
Construct the green''s function : Construct the green's function that satisfies xG''-(2x+1)G'+(x+1)G= ?(x-s), G(0,s)=G(1,s)=0
Explain globalization : Explain Globalization explains and explain at least four effects of globalization that impact your community and your organization

Reviews

Write a Review

 

Computer Engineering Questions & Answers

  Forming a report which show employee information

Form a report that show the employee information, show on the form you generated in 1) above. The report should display this information for all the users, sorted alphabetically in the ascending order by LastName.

  How might bpr be used in your organization

What is Business Process Reengineering (BPR)? Discuss how BPR might be used and describe the 'theoretical' results.

  Program declaring an integer variable

Write down a complete program that declares an integer variable, reads a value from keyboard into that variable.

  System analysis and design

In the System Analysis and Design: Design Patterns – How widely used are design patterns in today’s development environments.

  Does case or object-oriented design techniques used

consider the alternatives that were considered during the design stage of the project. What were the considerations in choosing the best alternative strategy.

  Creating the method

Assume we wish to form a method for class BinaryTree which decides whether two trees have same structure. The header of the method could be as follows: public boolean isIsomorphic(BinaryTreeInterface otherTree).

  What is steady-state cpi

What is steady-state CPI

  Generating class diagram and pseudocode

Develop a class named CustomerRecord which holds a customer number, name, and address. Incorporate different methods in order to set the values for each data field and output values for each data field.

  Data planning and enterprise modelling

Describe the major differences between two approaches for data planning and enterprise modelling and examine the integration? Why do these two methodologies usually produce several results?

  Program to print a sequence of 20 random die tosses

Write down a program which produces a sequence of 20 random die tosses in an array and which prints the die values.

  Definition of method dashedline

Write down the definition of the method dashedLine , with one parameter, an int. If parameter is negative or zero, method does nothing.

  Writing down the code

Suppose that the a, b and c are char variables has been declared. Write some code which reads the first character of next line into a.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd