21. februar 2012 - 21:47
#6
public class Count {
public static boolean isThreeSixes1(Dice d1, Dice d2, Dice d3, Dice d4) {
if( (d1.getValue() == 6 && d2.getValue() == 6 && d3.getValue() == 6)
|| (d1.getValue() == 6 && d2.getValue() == 6 && d4.getValue() == 6 )
|| (d1.getValue() == 6 && d3.getValue() == 6 && d4.getValue() == 6 )
|| (d2.getValue() == 6 && d3.getValue() == 6 && d4.getValue() == 6 ) ) {
return true;
} else {
return false;
}
}
public static boolean isThreeSixes2(Dice d1, Dice d2, Dice d3, Dice d4) {
return (d1.getValue() == 6 && d2.getValue() == 6 && d3.getValue() == 6)
|| (d1.getValue() == 6 && d2.getValue() == 6 && d4.getValue() == 6 )
|| (d1.getValue() == 6 && d3.getValue() == 6 && d4.getValue() == 6 )
|| (d2.getValue() == 6 && d3.getValue() == 6 && d4.getValue() == 6 );
}
public static boolean isThreeSixes3(Dice d1, Dice d2, Dice d3, Dice d4) {
int n6 = 0;
if(d1.getValue() == 6) n6++;
if(d2.getValue() == 6) n6++;
if(d3.getValue() == 6) n6++;
if(d4.getValue() == 6) n6++;
if(n6 >= 3) {
return true;
} else {
return false;
}
}
public static boolean isThreeSixes4(Dice d1, Dice d2, Dice d3, Dice d4) {
int n6 = 0;
if(d1.getValue() == 6) n6++;
if(d2.getValue() == 6) n6++;
if(d3.getValue() == 6) n6++;
if(d4.getValue() == 6) n6++;
return n6 >= 3;
}
public static boolean isThreeSixes5(Dice d1, Dice d2, Dice d3, Dice d4) {
if( ("" + d1.getValue() + d2.getValue() + d3.getValue() + d4.getValue()).replaceAll("[^6]", "").length() >= 3 ) {
return true;
} else {
return false;
}
}
public static boolean isThreeSixes6(Dice d1, Dice d2, Dice d3, Dice d4) {
return ("" + d1.getValue() + d2.getValue() + d3.getValue() + d4.getValue()).replaceAll("[^6]", "").length() >= 3;
}
public static void test(Dice d1, Dice d2, Dice d3, Dice d4) {
System.out.println(isThreeSixes1(d1, d2, d3 ,d4));
System.out.println(isThreeSixes2(d1, d2, d3 ,d4));
System.out.println(isThreeSixes3(d1, d2, d3 ,d4));
System.out.println(isThreeSixes4(d1, d2, d3 ,d4));
System.out.println(isThreeSixes5(d1, d2, d3 ,d4));
System.out.println(isThreeSixes6(d1, d2, d3 ,d4));
}
public static void main(String[] args) {
test(new Dice(6), new Dice(5), new Dice(6), new Dice(6));
test(new Dice(6), new Dice(5), new Dice(4), new Dice(6));
test(new Dice(6), new Dice(6), new Dice(6), new Dice(6));
}
}
class Dice {
private int value;
public Dice(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}