Question
Posting this again. Code won't run or compile. Please write in JAVA and use ENUM type to produce output. Posting the code at the bottom
Posting this again. Code won't run or compile. Please write in JAVA and use ENUM type to produce output. Posting the code at the bottom if you wish to look at for reference. Would prefer if new code was written, doesn't seem to make full sense. Edit if you can get to compile and run. Please provide pictures of output and comments with code to explain. Thank you!
Previous code that doesn't make sense:
import java.util.*;
public class SetFinder {
public enum Shape { DIAMOND, SQUIGGLE, OVAL }
public enum Fill { SOLID, STRIPED, OPEN }
public enum Color { RED, GREEN, MAGENTA }
private static class Card {
private final Shape shape;
private final Fill fill;
private final Color color;
public Card(Shape shape, Fill fill, Color color) {
this.shape = shape;
this.fill = fill;
this.color = color;
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
List
int cardNum = 1;
while (scan.hasNextLine()) {
String line = scan.nextLine();
Shape shape = shapeFromString(line.substring(0, 1));
Fill fill = fillFromString(line.substring(1, 2));
Color color = colorFromString(line.substring(2, 3));
cards.add(new Card(shape, fill, color));
}
List> sets = findSets(cards);
if (sets.isEmpty()) {
System.out.println("no sets");
} else {
for (List
for (int i = 0; i
System.out.print(set.get(i));
if (i != set.size() - 1) {
System.out.print(" ");
}
}
System.out.println();
}
}
}
private static Shape shapeFromString(String s) {
switch (s) {
case "D": return Shape.DIAMOND;
case "S": return Shape.SQUIGGLE;
case "O": return Shape.OVAL;
default: throw new IllegalArgumentException("Invalid shape: " + s);
}
}
private static Fill fillFromString(String s) {
switch (s) {
case "S": return Fill.SOLID;
case "T": return Fill.STRIPED;
case "O": return Fill.OPEN;
default: throw new IllegalArgumentException("Invalid fill: " + s);
}
}
private static Color colorFromString(String s) {
switch (s) {
case "R": return Color.RED;
case "G": return Color.GREEN;
case "M": return Color.MAGENTA;
default: throw new IllegalArgumentException("Invalid color: " + s);
}
}
private static boolean isSet(Card a, Card b, Card c) {
return (a.shape == b.shape && b.shape == c.shape ||
a.shape != b.shape && b.shape != c.shape && a.shape != c.shape) &&
(a.fill != b.fill && b.fill != c.fill && a.fill != c.fill) &&
(a.color == b.color && b.color == c.color ||
a.color != b.color && b.color != c.color && a.color != c.color);
}
private static List> findSets(List
List> sets = new ArrayList();
for (int i = 0; i
for (int j = i + 1; j
for (int k = j + 1; k
if (isSet(cards.get(i), cards.get(j), cards.get(k))) {
List
set.add(i + 1);
set.add(j + 1);
set.add(k + 1);
sets.add(set);
}
}
}
}
return sets;
}
Background Set is a game played with 34 cards. The cards contain diamonds, squiggles, or ovals. This symbols are drawn using either a solid, striped, or open fill style. Each symbol's color is either red, green, or magenta. On a given card, all symbols are of the same type, same color, and have the same fill style. To make a set, you need three cards for which all characteristics are either the same or pairwise different. For instance, cards where the first shows striped red ovals, the second shows striped green squiggles, and the third shows striped magenta diamonds form a set. They show ovals, squiggles, and diamonds (each shows a different shape); they use colors red, green, and magenta (different colors); and lastly, they all share the same fill style: striped. The Task Write a program that finds all sets that can be made from twelve given cards. Sample Input and Output Input The input to your program will consist of lines, each containing strings representing cards, each consisting of four characters where corresponding to the number of symbols. corresponding to diamonds (D), squiggles (S), and ovals (O). corresponding to solid (S), striped (T), and open (O) fill styles. corresponding to red (R), green (G), and magenta (M). Think of the cards as being arranged in the input as follows: Output all sets you can find, one per line. For each set, output the numbers of the card in the set in sorted order. The sets should be listed in sorted order using the number of their first card, breaking ties using the numbers of the second and third card in the set. If no sets can be formed, output "no sets". (Do not include any punctuation.) The sample input/output corresponds to the illustration. Sample Input and Output Sample Input 3DTG 3DOM 2DSG 1SOM 1DTG 2OTR 3DOR 3STG 2DSM 3SSM 3OTG 1DTM Sample Output 123567897781011121291211Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started