/** Chuck-a-luck: An Impromptu Program
*
* AUTHORS
*
* John P. Spurgeon with support from Akil, Jonathan, Kai, Katherine, and Leon.
*
* VERSION LINEAGE
*
* 0. https://apcsafreeresponsequestions.blogspot.com/2019/02/original-chuck-a-luck.html. (ORIGINAL)
* 1. https://apcsafreeresponsequestions.blogspot.com/2019/02/chuck-a-luck.html. (EXERCISES)
* 2. https://apcsafreeresponsequestions.blogspot.com/2019/02/chuck-a-luck-answers.html. (ANSWERS TO EXERCISES 1-4)
* 3. https://apcsafreeresponsequestions.blogspot.com/2019/02/chuck-a-luck-or-risk.html. (ANSWERS TO EXERCISES 1-5)
*
* DESCRIPTION
*
* This is the original version of Chuck-a-luck created by Mr. Spurgeon and a
* posse of precocious programmers at MiT School in Beaverton, Oregon on
* Monday, 11 February 2019 between 4:30 and 5:30 PM (PST). It become the basis
* for subsequent versions used by Mr. Spurgeon’s AP Computer Science A
* students at Valley Catholic High School.
*/
import java.util.*;
class Dice {
private int value;
public Dice roll() {
value = (int)(1 + Math.random() * 6);
return this;
}
public int valueOf() {
return value;
}
public String toString() {
String d = "";
switch (value)
{
case 1:
d += "-------------" + '\n';
d += "| |" + '\n';
d += "| |" + '\n';
d += "| * |" + '\n';
d += "| |" + '\n';
d += "| |" + '\n';
d += "-------------" + '\n';
break;
case 2:
d += "-------------" + '\n';
d += "| |" + '\n';
d += "| * |" + '\n';
d += "| |" + '\n';
d += "| * |" + '\n';
d += "| |" + '\n';
d += "-------------" + '\n';
break;
case 3:
d += "-------------" + '\n';
d += "| |" + '\n';
d += "| * |" + '\n';
d += "| * |" + '\n';
d += "| * |" + '\n';
d += "| |" + '\n';
d += "-------------" + '\n';
break;
case 4:
d += "-------------" + '\n';
d += "| |" + '\n';
d += "| * * |" + '\n';
d += "| |" + '\n';
d += "| * * |" + '\n';
d += "| |" + '\n';
d += "-------------" + '\n';
break;
case 5:
d += "-------------" + '\n';
d += "| |" + '\n';
d += "| * * |" + '\n';
d += "| * |" + '\n';
d += "| * * |" + '\n';
d += "| |" + '\n';
d += "-------------" + '\n';
break;
case 6:
d += "-------------" + '\n';
d += "| |" + '\n';
d += "| * * |" + '\n';
d += "| * * |" + '\n';
d += "| * * |" + '\n';
d += "| |" + '\n';
d += "-------------" + '\n';
break;
default:
}
return d;
}
}
public class ChuckALuck {
private static final String
triple = "Triple",
big = "Big",
small = "Small",
field = "Field";
private static int v1, v2, v3;
private static List results = new LinkedList();
private static void play()
{
Dice dice = new Dice();
v1 = dice.roll().valueOf();
System.out.print(dice);
v2 = dice.roll().valueOf();
System.out.print(dice);
v3 = dice.roll().valueOf();
System.out.print(dice);
}
public static void main(String args[]) {
System.out.println("Chuck-a-luck");
play();
int sum = v1 + v2 + v3;
System.out.println("Sum: " + sum);
if (v1 == v2 && v2 == v3) {
results.add(triple);
}
else if (sum >= 11) {
results.add(big);
}
else if (sum <= 10 ) {
results.add(small);
}
if (sum < 8 || sum > 12) {
results.add(field);
}
for (int i = 0; i < args.length; i++) {
if (results.indexOf(args[i]) >= 0) {
System.out.println("Player " + i + " won!");
}
}
}
}