Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The number of permutations of n items is computed as follows: n! = n * (n - 1)!

ID: 3591208 • Letter: T

Question

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:|

Complete the getCount method so that it counts the number of permutations for n items by recursively constructing a PermutationCounter object 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

Explanation / Answer

class PermutationCounter { private int n; PermutationCounter(int numberOfItems) { n = numberOfItems; } public long getCount() { // Your work here if(n==0) return 1; else{ // recurssive factorial method n=n-1; return (long)(n+1)* getCount(); } }//end getCount method } // end class PermutationCounter 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 ***="+counter.getCount()); } // end main } // end class Lab_Project_11

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote