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

pbc8 dy46 #7

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

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ResourceBundle;

import roulette.bets.*;
import util.ConsoleReader;

public class Factory {
private static final String PREFIX = "roulette.bets.";
private String[] myPossibleBets = {
"RedBlack",
"OddEven",
"ThreeConsecutive",
};

public Bet promptForBet() throws NoSuchMethodException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
System.out.println("You can make one of the following types of bets:");
for (int k = 0; k < myPossibleBets.length; k++) {
System.out.println(String.format("%d) %s", (k + 1), myPossibleBets[k]));
}
int response = ConsoleReader.promptRange("Please make a choice", 1, myPossibleBets.length);
String className = PREFIX + myPossibleBets[response-1];
Class[] params = new Class[]{String.class, Integer.class};
Constructor betCon = Class.forName(className).getConstructor(params);
String description = ResourceBundle.getBundle("bets").getString(myPossibleBets[response-1]).split(",")[0];
int odds = Integer.parseInt(ResourceBundle.getBundle("bets").getString(myPossibleBets[response-1]).split(",")[1]);
return (Bet) betCon.newInstance(new Object[]{new String(description), new Integer(odds)});
}
}
27 changes: 0 additions & 27 deletions src/roulette/OddEven.java

This file was deleted.

26 changes: 0 additions & 26 deletions src/roulette/RedBlack.java

This file was deleted.

27 changes: 0 additions & 27 deletions src/roulette/ThreeConsecutive.java

This file was deleted.