project0
Class LuckTester

java.lang.Object
  |
  +--project0.LuckTester

public class LuckTester
extends java.lang.Object

Does the God/Godess of Luck know you? A class to help answer this urgent question.

Author:
dickey 143-03wi

Constructor Summary
LuckTester()
          Creates a new instance of LuckTester
 
Method Summary
 boolean checkInitials(java.lang.String initials)
          Check that a pair of initials is suitable for presentation to the God/Goddess of Luck.
 int tryUntilSuccess(java.lang.String initials)
          Given a person's initials, how long does it take the God/Goddess of luck to recognize that person? Algorithm: Generate pairs of characters randomly until the desired initials are observed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LuckTester

public LuckTester()
Creates a new instance of LuckTester

Method Detail

checkInitials

public boolean checkInitials(java.lang.String initials)
Check that a pair of initials is suitable for presentation to the God/Goddess of Luck.

Parameters:
initials - A person's initials: must be exactly two uppercase English letters.
Returns:
true iff both initials are valid (thus avoiding the wrath of the gods).

tryUntilSuccess

public int tryUntilSuccess(java.lang.String initials)
Given a person's initials, how long does it take the God/Goddess of luck to recognize that person? Algorithm: Generate pairs of characters randomly until the desired initials are observed. To avoid infinite loops, at most 1,000,000 pairs are tested.

Parameters:
initials - A string of exactly two uppercase alphabetic characters; invalid initials risk inciting the wrath of the gods.
Returns:
the number of random pairs which were generated before the initials were generated. The minimum possible value is 0, which would mean the the very first pair generated was the pair requested.