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

  What are race situations difficult to debug

assume the legislature in your state is debating the adoption of UCITA and you have been known as an expert witness. What are the three most important ideas you want your legislators to get from the testimony.

  Relationship of tactical-strategic and operational plans

Explain what is meant by the relationship of tactical, strategic, and operational plans, and their individual planning horizons as applied to the telecommunications field.

  Data storage problem in the database tables

You must select the data storage problem of your interest and recognize the different pieces of the data which must be stored within the database.

  Plan a use case diagram to represent actors

As Dewey Dezmal enters high-ceilinged, wood-paneled reading room of the Ruminski Public Library, a young woman, seated at a long, oak table, pokes her head out from behind the monitor, sees him and stands, saying, "Welcome. I'm Peri Otticle, the d..

  Explain differences between the various graphic formats

explain differences between the various graphic formats. express some ways to increase your site's search engine ranking.

  Performance improvement for the least amount of money

suppose in your computer, the most of your daytime processes spend 75 percent of their time running in the CPU and 25% waiting for service from disk.

  Formal mission statement about soft-wear, limited

Explain how do the information systems help the people working individually and in groups make the decisions more efficiently? Write down a formal mission statement about the Soft-Wear, Limited (SWL).

  Program dealing with selection of five random cards

Generate a program which deals with the five random cards.

  Detecting problem behind slow system booting

Suppose you have observed that your system is performing slower than the usual. Which system resources are likely to be at the root of the problem?

  Write down python program

Write down Python program

  Explaining the binary tree

The left spine of the binary tree is a path starting at root and following only left-child pointers down to a leaf. State the expected number of nodes in left spine of an n-node treap. What is the expected number of leaves in an n-node treap?

  Factors in selecting suitable data type

Explain the factors in selecting the suitable data type for some value? Which of these is most significant?

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