Skip to content
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>
3 changes: 3 additions & 0 deletions src/roulette/Bets.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OddEven = Odd or Even,1
RedBlack = Red or Black,1
ThreeConsecutive = Three in a Row,11
64 changes: 64 additions & 0 deletions src/roulette/Factory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package roulette;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import roulette.bets.OddEven;
import roulette.bets.RedBlack;
import roulette.bets.ThreeConsecutive;
import util.ConsoleReader;

public class Factory {

List<Bet> myBets;
private static ResourceBundle myResourceBundle = ResourceBundle.getBundle("roulette/Bets");

public Factory() {
// TODO Auto-generated constructor stub
myBets = new ArrayList<Bet>();

}

public static Bet createBet(String type) {

Class c;
Bet bet;
try {
c = Class.forName("roulette."+ type );
String[] args = myResourceBundle.getString(type).split(",");
bet = (Bet)c.getConstructor(String.class, Integer.class).newInstance(args[0], Integer.parseInt(args[1]));
return bet;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(IllegalAccessException e){
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(InvocationTargetException e){
e.printStackTrace();
} catch(NoSuchMethodException e){
e.printStackTrace();
}

return null;
}


public List<Bet> getBets(){
return myBets;
}

private Bet promptForBet () {
System.out.println("You can make one of the following types of bets:");
for (int k = 0; k < myBets.size(); k++) {
System.out.println(myResourceBundle.getKeys());
}
int response = ConsoleReader.promptRange("Please make a choice", 1, myBets.size());
return myBets.get(response - 1);
}

}