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

mmc56 tln11 #22

Open
wants to merge 1 commit 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 @@
OddEven=.56, odd and even bet
RedBlack= .76, red and black bet
ThreeConsecutive= .88, three consecutive bet
8 changes: 4 additions & 4 deletions src/roulette/Bet.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
*/
public class Bet {
private String myDescription;
private int myOdds;
private double myOdds;

/**
* Constructs a bet with the given name and odds.
*
* @param description name of this kind of bet
* @param name of this kind of bet
* @param odds odds given by the house for this kind of bet
*/
public Bet (String description, int odds) {
public Bet (double odds, String description) {
myDescription = description;
myOdds = odds;
}

/**
* @return odds given by the house for this kind of bet
*/
public int getOdds () {
public double getOdds () {
return myOdds;
}

Expand Down
39 changes: 39 additions & 0 deletions src/roulette/Factory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package roulette;

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

public class Factory {

private String[] classnames = {"OddEven","RedBlack", "ThreeConsecutive"};
private static ResourceBundle myResources = ResourceBundle.getBundle("Resources/Bets");

public static Bet createBet(String classname){
String[] betArguments = myResources.getString(classname).split(", ");
double odds = Double.parseDouble(betArguments[0]);
String descriptor = betArguments[1];
Bet bet = null;
switch (classname){
case "OddEven":
bet = new OddEven(odds, descriptor);
break;
case "RedBlack":
bet = new RedBlack(odds, descriptor);
break;
case "ThreeConsecutive":
bet = new ThreeConsecutive(odds, descriptor);
break;
default:
return null;
}
return bet;
}

public static Bet createBetwithReflection(String classname) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Class<?> clazz = Class.forName((classname));
Bet bet = (Bet) clazz.getConstructor().newInstance();
return bet;
}
}
6 changes: 3 additions & 3 deletions src/roulette/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class Game {
private static final String DEFAULT_NAME = "Roulette";
// bets player can make
private Bet[] myPossibleBets = {
new Bet("Red or Black", 1),
new Bet("Odd or Even", 1),
new Bet("Three in a Row", 11)
new Bet(1, "Red or Black"),
new Bet(1, "Odd or Even"),
new Bet(11, "Three in a Row")
};
private Wheel myWheel;

Expand Down
13 changes: 13 additions & 0 deletions src/roulette/OddEven.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package roulette;

public class OddEven extends Bet{

public OddEven() {
// TODO Auto-generated constructor stub
super(0, "Hi");
}

public OddEven(double odds, String description){
super(odds, description);
}
}
14 changes: 14 additions & 0 deletions src/roulette/RedBlack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package roulette;

public class RedBlack extends Bet{

public RedBlack() {
// TODO Auto-generated constructor stub
super(0, "Hi");
}

public RedBlack(double odds, String description){
super(odds, description);
}

}
13 changes: 13 additions & 0 deletions src/roulette/ThreeConsecutive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package roulette;

public class ThreeConsecutive extends Bet{

public ThreeConsecutive() {
// TODO Auto-generated constructor stub
super(0, "Hi");
}

public ThreeConsecutive(double odds, String description){
super(odds, description);
}
}