Question: solve each parts please Start this lab by creating a NetBeans project named Lab_Project_11 . Once the project finishes loading, add an additional Java class
solve each parts please
Start this lab by creating a NetBeans project named Lab_Project_11.
Once the project finishes loading, add an additional Java class named PermutationCounter.
Lab 11.1
The number of permutations of n items is computed as follows: n! = n * (n - 1)! for n > 0; Here, the number of permutations of n items is written as n!, which is pronounced "n factorial". It is easy to see why this formula is true. There are n choices for placing the first item. For each of these choices, there are n - 1 places left for the other items. When n is 1, there is only one permutation of a single item. Hence 1! = 1 It is also convenient to set 0! = 1 From this definition, compute the value of 5! and show your work, in the space provided below.
Lab 11.2
Copy/paste the highlighted code below into your PermutationCounter.java source file:|
public class PermutationCounter { private int n; public PermutationCounter(int numberOfItems) { n = numberOfItems; } public long getCount() { // Your work here } } // end class PermutationCounter
Complete the getCount method so that it counts the number of permutations for n items by recursively constructing a PermutationCounterobject to count the permutations of smaller number of items (i.e., n-1).
Lab 11.3
To test your PermutationCounter class, add the highlighted code below to your main method, replacing the output with your hand-computed value for 5! from Lab 11.1 where indicated:
public class Lab_Project_11 { public static void main(String[] args) { PermutationCounter counter = new PermutationCounter(5); System.out.println(counter.getCount()); System.out.println("Expected: *** replace with the value calculated for 5! in lab 11.1 ***"); } // end main } // end class Lab_Project_11
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
