![]() |
![]() |
|
home—info—archive—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
Die regular = new Die(6);
Die icosohedron = new Die(20);
Die weird = new Die(3);
|
class Coin {
// ...Your fields here.
/** If our internal die shows 1, we'll consider this Coin as showing tails. */
private static int TAILS == 1;
/** If our internal die shows 2, we'll consider this Coin as showing heads. */
private static int HEADS == 2;
/** Coin constructor.
*/
Coin() {
}
/** Flip the coin.
*/
void flip() {
}
/** Return whether or not the coin shows heads.
* @return whether or not the coin shows heads.
*/
boolean isHeads() {
return false;
}
/** Return whether or not the coin shows tails.
* @return whether or not the coin shows tails.
*/
boolean isTails() {
return false;
}
/** Return "T" or "H", indicating showing tails or heads (resp.).
* @Return "T" or "H", indicating showing tails or heads (resp.).
*/
String toString() {
return "lala";
}
}
|
public class CoinTest {
/** Create some dice and print out some rolls.
*/
public static void printDieTest() {
Die d6 = new Die(); // no-arg constructor: 6 sides.
Die d12 = new Die(12);
Die d100 = new Die(100);
d6.roll();
d12.roll();
d100.roll();
System.out.println( "d6 rolled " + d6.getFace() + ";"
+ "d12 rolled " + d12.getFace() + ";"
+ "d100 rolled " + d100.getFace() + "." )
d6.roll();
d12.roll();
d100.roll();
System.out.println( "d6 rolled " + d6.getFace() + ";"
+ "d12 rolled " + d12.getFace() + ";"
+ "d100 rolled " + d100.getFace() + "." )
}
/** Create a coin and print out some flips.
*/
public static void printCoinTest() {
Coin c = new Coin();
c.flip();
System.out.println( "Toss 1: " + c.toString() );
c.flip();
System.out.println( "Toss 2: " + c.toString() );
c.flip();
System.out.println( "Toss 3: " + c.toString() );
}
|
home—info—archive—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
| ©2008, Ian Barland, Radford University Last modified 2008.Mar.24 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |