Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

klo14 and add36 #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion src/roulette/Bet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
55 changes: 55 additions & 0 deletions src/roulette/BetFactory.java
Original file line number Diff line number Diff line change
@@ -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<Bet> 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<Bet>) 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;
}
}
3 changes: 3 additions & 0 deletions src/roulette/BetTypes.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RedorBlack = RedBlack,1
OddorEven = OddEven,1
ThreeinaRow = ThreeConsecutive,11
2 changes: 1 addition & 1 deletion src/roulette/Wheel.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private String getColor () {
}

// @return number of the current spot on the wheel
private int getNumber () {
int getNumber () {
return myValue;
}

Expand Down