diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/roulette/Bet.java b/src/roulette/Bet.java index 15d54a2..9477887 100755 --- a/src/roulette/Bet.java +++ b/src/roulette/Bet.java @@ -38,7 +38,7 @@ public String toString () { /** * Place bet by prompting user for the specific information need to complete this bet. */ - public abstract void place (); + public abstract String place (); /** * Checks if bet is won or lost given result of spinning the wheel. diff --git a/src/roulette/BetFactory.java b/src/roulette/BetFactory.java new file mode 100644 index 0000000..8608c8b --- /dev/null +++ b/src/roulette/BetFactory.java @@ -0,0 +1,55 @@ +package roulette; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; + +import roulette.bets.OddEven; +import roulette.bets.RedBlack; +import roulette.bets.ThreeConsecutive; + +public class BetFactory { + private ResourceBundle myBundle; + public Bet getBet(String betType) { + Constructor myConstructor = null; + Bet myInstance = null; + + myBundle = ResourceBundle.getBundle("roulette/BetTypes.properties"); + String myClassName = myBundle.getString(betType).split(",")[0]; + int myClassInt = Integer.parseInt(myBundle.getString(betType).split(",")[1]); + + try { + try { + myConstructor = (Constructor) Class.forName("roulette.bets"+myClassName).getConstructor(String.class,Integer.class); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + myConstructor.setAccessible(true); + try { + myInstance = myConstructor.newInstance(betType,myClassInt); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return myInstance; + } +} diff --git a/src/roulette/BetTypes.properties b/src/roulette/BetTypes.properties new file mode 100644 index 0000000..21b1ffa --- /dev/null +++ b/src/roulette/BetTypes.properties @@ -0,0 +1,3 @@ +RedorBlack = RedBlack,1 +OddorEven = OddEven,1 +ThreeinaRow = ThreeConsecutive,11 \ No newline at end of file diff --git a/src/roulette/Wheel.java b/src/roulette/Wheel.java index 00b3f68..7dbabcb 100755 --- a/src/roulette/Wheel.java +++ b/src/roulette/Wheel.java @@ -96,7 +96,7 @@ private String getColor () { } // @return number of the current spot on the wheel - private int getNumber () { + int getNumber () { return myValue; }