package comp1110.exam;
import java.util.*;
Copyright By PowCoder代写 加微信 powcoder
* COMP1110 Final Exam, Question 1.3
public class Q1CropRotation {
* Each Vegetable is assigned to one of four groups.
public enum Group {
LEGUME, BRASSICA, ALLIUM, FRUITING
public static class Vegetable {
String name;
Group group;
public Vegetable(String name, Group group) {
this.name = name;
this.group = group;
public String toString() {
return name + ” (” + group.name().toLowerCase() + “)”;
* Get all valid crop rotations that can be composed from the provided
* set of vegetable crops for the given number of seasons.
* A crop rotation is a sequence of vegetable crops to plant.
* One crop is planted per season, and any crop may be planted at most once.
* Crops must be planted in order of their Group according to the following
* – a LEGUME may only be followed by a BRASSICA;
* – a BRASSICA may only be followed by an ALLIUM;
* – an ALLIUM may only be followed by a FRUITING crop; and
* – a FRUITING crop may only be followed by a LEGUME.
* For example, the call
* getAllRotations([Tomato (fruiting), Onion (allium)], 2)
* returns a set containing a single rotation:
* – [Onion (allium), Tomato (fruiting)]
* because an ALLIUM may only be followed by a fruiting crop.
* The call
* getAllRotations([Tomato (fruiting), Kale (brassica), Onion (allium), Pea (legume)], 4)
* returns a set containing four rotations:
* – [Kale (brassica), Onion (allium), Tomato (fruiting), Pea (legume)]
* – [Onion (allium), Tomato (fruiting), Pea (legume), Kale (brassica)]
* – [Pea (legume), Kale (brassica), Onion (allium), Tomato (fruiting)]
* – [Tomato (fruiting), Pea (legume), Kale (brassica), Onion (allium)]
* If no valid crop rotation can be found, an empty list is returned.
* For example, the call:
* getAllRotations([Tomato (fruiting), (brassica)], 2)
* returns an empty set, because a FRUITING crop cannot be followed by
* a BRASSICA, and a BRASSICA cannot be followed by a FRUITING crop.
* @param crops the set of vegetable crops from which to construct a rotation
* @param seasons the number of seasons
* @return the set of all possible rotations of the provided crops for the
* given number of seasons
public static Set> getAllRotations(Set
// FIXME complete this method
return null;
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com