Question: In JAVA please define the following 2 recursion methods In the class Orders.java write the following method. Here is the Java code for class Orders
In JAVA please define the following 2 recursion methods

In the class Orders.java write the following method.

Here is the Java code for class Orders
import java.util.*; public class Orders{
// Produce all possible orders of specials with replacement; // currentOrder is the current order of specials and maxSize is // the maximum length desired. allOrderings accumulates string // results as they are found. public static void orders(ArrayList
// Haven't reached maxSize so add each possible special to the // end of allOrders and recurse down to continue the // search. Remove the special after finishing the recursive call // to replace it with another special. for(String special : specials){ currentOrder.add(special); orders(specials, currentOrder, maxSize, allOrders); currentOrder.remove( currentOrder.size()-1 ); } return; }
// Produce all possible orders of specials with replacement but // ensure that no adjacent specials are identical (no adjacent // repeats). public static void ordersNoAdj(ArrayList
// Produce all possible orders of specials WITHOUT replacement: each // special in an order in allOrders should be unique. public static void ordersNoRepeats(ArrayList
public static void main(String args[]){ ArrayList
ArrayList
System.out.printf("%d orders ",allOrders.size()); for(String order : allOrders){ System.out.println(order); }
System.out.println();
// Now without adjacent repeats allOrders.clear(); currentOrder.clear(); ordersNoAdj(specials, currentOrder, maxSize, allOrders);
System.out.printf("%d orders ",allOrders.size()); for(String order : allOrders){ System.out.println(order); }
System.out.println();
// Now without any repeats allOrders.clear(); currentOrder.clear(); ordersNoRepeats(specials, currentOrder, maxSize, allOrders);
System.out.printf("%d orders ",allOrders.size()); for(String order : allOrders){ System.out.println(order); } }
}
In the class Orders.java write the following method. // Produce all possible orders of specials with replacement but // ensure that no adjacent specials are identical (no adjacent // repeats). public static void ordersNoAdj (ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
