SlideShare a Scribd company logo
I don't know what is wrong with this roulette program I can't seem to get it to run.
Game Class:
public class Game {
public static void main(String[] args) {
Table table = new Table();
BinBuilder bb = new BinBuilder();
Outcome black = new Outcome("Black", 35);
Bet bet = new Bet(10, black);
table.placeBet(bet);
Bin bin = bb.wheel.get(8);
System.out.println(bin.toString());
System.out.println(table.bets.toString());
System.out.println(black.toString());
ListIterator i = table.bets.listIterator();
Iterator b = bin.outcomes.iterator();
while(i.hasNext()) {
System.out.println(i.next().outcome.name.toString());
while(b.hasNext()){
System.out.println(b.next().name.toString());
if(i.next().outcome.equals(b.next())){
System.out.println("Win!");
}
else{
System.out.println("Win :/");
}
}
}
}
}
Player Class
public class Player {
public Table table;
public Outcome black;
public Bet bet;
public Player(Table table) {
table = new Table();
black = new Outcome("Black", 1);
}
void placeBets() {
Bet bet = new Bet(100, black);
table.placeBet(bet);
}
void win(Bet bet) {
System.out.println("You've won: " + bet.winAmount());
}
void lose(Bet bet) {
System.out.println("You lost!" + bet.loseAmount() + ":/");
}
}
Outcome class
public class Outcome implements Comparable {
public String name;
public int odds;
public Outcome(String name, int odds){
this.name = name;
this.odds = odds;
}
public int winAmount(int amount){
return amount*this.odds;
}
public boolean equals(Outcome other){
return (this.name.equals(other.name));
}
public String toString() {
Object[] values= { name, new Integer(odds) };
String msgTempl= "{0} ({1}:1)";
return MessageFormat.format( msgTempl, values );
}
@Override
public int compareTo(E arg0) {
if(this.equals(arg0)){
return 0;
}
return 1;
}
}
Table Class
public class Table {
public int limit = 1000;
public LinkedList bets;
public Table() {
bets = new LinkedList();
}
public boolean isValid(Bet bet) {
int sum = 0;
for(Bet bett: bets) {
sum += bett.amountBet;
}
return (sum>limit);
}
public void placeBet(Bet bet) {
bets.add(bet);
}
ListIterator iterator() {
return bets.listIterator();
}
}
Wheel Class
public class Wheel extends TreeSet {
Vector bins;
NonRandom rng;
Set all_outcomes;
Wheel(NonRandom rng){
this.rng = rng;
rng = new NonRandom();
all_outcomes = new TreeSet();
bins = new Vector(38);
for (int i=0; i<38; i++){
bins.add(i, new Bin());
}
}
Bin next(){
int rand = rng.next(38);
return bins.elementAt(rand);
}
Bin get(int bin){
return bins.elementAt(bin);
}
public Outcome getOutcome( String name ){
TreeSet result= new TreeSet();
for( Iterator i = all_outcomes.iterator(); i.hasNext(); ) {
Outcome oc= i.next();
if( oc.name.contains(name) ) {result.add( oc );}
}
return result.first();
}
public void addOutcome(int bin, Outcome outcome) {
all_outcomes.add(outcome);
this.bins.elementAt(bin).add(outcome);
}
}
Bet Class
public class Bet {
public int amountBet;
public Outcome outcome;
public Bet(int amount, Outcome outcome) {
this.outcome = outcome;
this.amountBet = amount;
}
public int winAmount() {
int winAmount = this.outcome.odds * this.amountBet;
return winAmount + this.amountBet;
}
public int loseAmount() {
int loseAmount = this.amountBet;
return loseAmount;
}
public String toString() {
return this.amountBet+" on "+"["+this.outcome.toString()+"]";
}
}
Bin Class
public class Bin {
public TreeSet outcomes;
int i =0;
Bin(){
outcomes = new TreeSet();
}
Bin(Outcome[] outcomes){
this();
for(Outcome anOutcome: outcomes){
add(anOutcome);
}
}
Bin(Collection outcomes){
this();
for(Outcome anOutcome: outcomes){
add(anOutcome);
}
}
void add(Outcome outcome){
this.outcomes.add(outcome);
}
public String toString(){
String string ="";
Iterator it1 =this.outcomes.iterator();
while(it1.hasNext()){
string += "["+it1.next().toString()+"]";
}
return string;
}
}
BinBuilder Class
public class BinBuilder {
public Wheel wheel;
public NonRandom nrng;
public BinBuilder() {
this.nrng = new NonRandom();
this.wheel = new Wheel(nrng);
buildBins(wheel);
}
public Wheel getWheel() {
return wheel;
}
private void buildBins(Wheel wheel){
straightBets(wheel);
splitBets(wheel);
streetBets(wheel);
cornerBets(wheel);
lineBets(wheel);
dozenBets(wheel);
columnBets(wheel);
evenMoneyBets(wheel);
}
void straightBets(Wheel wheel){
for(int i = 1; i<37; i++){
Outcome outcome = new Outcome(""+i, 35);
String u = ""+i;
wheel.addOutcome(i , outcome);
}
}
void splitBets(Wheel wheel){
for(int r = 0; r<12; r++){
int n = (3*r) +1;
Outcome outcome = new Outcome("'"+n+", "+n+1+"'", 17);
wheel.addOutcome(n , outcome);
wheel.addOutcome(n+1 , outcome);
n = (3*r) +2;
Outcome outcome2 = new Outcome("'"+n+", "+n+1+"'", 17);
wheel.addOutcome(n , outcome2);
wheel.addOutcome(n+1, outcome2);
}
for(int n = 1; n<34; n++){
Outcome outcomen = new Outcome(n+", "+n+3, 17);
wheel.addOutcome(n , outcomen);
wheel.addOutcome(n+3 , outcomen);
}
}
void streetBets(Wheel wheel){
for(int r = 0; r<12; r++){
int n = (3*r) +1;
Outcome outcome = new Outcome(""+n, 11);
wheel.addOutcome(n , outcome);
wheel.addOutcome(n+1 , outcome);
wheel.addOutcome(n+2 , outcome);
}
}
void cornerBets(Wheel wheel){
for(int r = 0; r<11; r++){
int n = (3*r) +1;
Outcome outcome = new Outcome(n +", " +n +1+", " +n +3+", " +n +4, 8);
wheel.addOutcome(n , outcome);
wheel.addOutcome(n+1 , outcome);
wheel.addOutcome(n+3 , outcome);
wheel.addOutcome(n+4 , outcome);
int s = (3*r) +2;
Outcome outcome2 = new Outcome(s +", "+ s +1+", "+ s+3+", "+ s +4, 17);
wheel.addOutcome(n , outcome2);
wheel.addOutcome(n+1, outcome2);
wheel.addOutcome(n+3, outcome2);
wheel.addOutcome(n+4, outcome2);
}
}
void lineBets(Wheel wheel){
for(int r = 0; r<10; r++){
int n = (3*r) +1;
Outcome outcome = new Outcome(n+", "+ (n +1)+","+ (n +2)+", "+ (n +3)+", "+ (n
+4)+", "+ (n +5), 5);
wheel.addOutcome(n , outcome);
wheel.addOutcome(n+1 , outcome);
wheel.addOutcome(n+2 , outcome);
wheel.addOutcome(n+3 , outcome);
wheel.addOutcome(n+4 , outcome);
wheel.addOutcome(n+5 , outcome);
}
}
void dozenBets(Wheel wheel){
for(int d = 0; d<3; d++){
Outcome outcome = new Outcome(""+(d+1), 2);
for(int m = 0; m<12; m++){
wheel.addOutcome(12*d+m+1 , outcome);
}
}
}
void columnBets(Wheel wheel){
for(int c = 0; c<3; c++){
Outcome outcome = new Outcome(""+c+1,2);
for(int r = 0; r<12; r++){
wheel.addOutcome((3*r)+c+1 , outcome);
}
}
}
void evenMoneyBets(Wheel wheel){
for(int n = 0; n<37; n++){
if(n>=1 && n<19){
Outcome outcome_l = new Outcome("Low",1);
wheel.addOutcome(n , outcome_l);
}
else {
Outcome outcome_h = new Outcome("High",1);
wheel.addOutcome(n , outcome_h);
}
if(n%2==0){
Outcome outcome_e = new Outcome("Even",1);
wheel.addOutcome(n , outcome_e);
}
else {
Outcome outcome_o = new Outcome("Odd",1);
wheel.addOutcome(n , outcome_o);
}
int[] Red = {1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36};
if (Arrays.binarySearch(Red, n) >= 0){
Outcome outcome_r = new Outcome("Red",1);
wheel.addOutcome(n , outcome_r);
}
else {
Outcome outcome_b = new Outcome("Black",1);
wheel.addOutcome(n , outcome_b);
}
}
}
}
NonRandom Class
public class NonRandom {
private long value;
public void NonRandom(){
value = 0;
}
public int next(int bits) {
return (int) value;
}
public void setSeed(long value) {
this.value = value;
}
}
Solution
In the main method you are calling the i.next() and b.next() method twice in a loop which cause
an error. I have made the changes. Kindly go through the changes that i have made.
------------------------------------------------code--------------------------------------------------------------
---------------------------------
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;
import java.util.LinkedList;
public class Game {
public static void main(String[] args) {
Table table = new Table();
BinBuilder bb = new BinBuilder();
Outcome black = new Outcome("Black", 35);
Bet bet = new Bet(10, black);
table.placeBet(bet);
Bin bin = bb.wheel.get(8);
System.out.println(bin.toString());
System.out.println(table.bets.toString());
System.out.println(black.toString());
ListIterator i = table.bets.listIterator();
Iterator b = bin.outcomes.iterator();
while(i.hasNext()) {
Outcome outcome=i.next().outcome;
System.out.println(outcome);
while(b.hasNext()){
Outcome binOutcome=b.next();
System.out.println(binOutcome);
if(outcome.equals(binOutcome)){
System.out.println("Win!");
}
else{
System.out.println("Win :/");
}
}
}
}
}
class Player {
public Table table;
public Outcome black;
public Bet bet;
public Player(Table table) {
table = new Table();
black = new Outcome("Black", 1);
}
void placeBets() {
Bet bet = new Bet(100, black);
table.placeBet(bet);
}
void win(Bet bet) {
System.out.println("You've won: " + bet.winAmount());
}
void lose(Bet bet) {
System.out.println("You lost!" + bet.loseAmount() + ":/");
}
}
class Outcome implements Comparable {
public String name;
public int odds;
public Outcome(String name, int odds){
this.name = name;
this.odds = odds;
}
public int winAmount(int amount){
return amount*this.odds;
}
public boolean equals(Outcome other){
return (this.name.equals(other.name));
}
public String toString() {
Object[] values= { name, new Integer(odds) };
String msgTempl= "{0} ({1}:1)";
return MessageFormat.format( msgTempl, values );
}
@Override
public int compareTo(E arg0) {
if(this.equals(arg0)){
return 0;
}
return 1;
}
}
class Table {
public int limit = 1000;
public LinkedListbets;
public Table() {
bets = new LinkedList();
}
public boolean isValid(Bet bet) {
int sum = 0;
for(Bet bett: bets) {
sum += bett.amountBet;
}
return (sum>limit);
}
public void placeBet(Bet bet) {
bets.add(bet);
}
ListIterator iterator() {
return bets.listIterator();
}
}
class Wheel extends TreeSet {
Vector bins;
NonRandom rng;
Set all_outcomes;
Wheel(NonRandom rng){
this.rng = rng;
rng = new NonRandom();
all_outcomes = new TreeSet();
bins = new Vector(38);
for (int i=0; i<38; i++){
bins.add(i, new Bin());
}
}
Bin next(){
int rand = rng.next(38);
return bins.elementAt(rand);
}
Bin get(int bin){
return bins.elementAt(bin);
}
public Outcome getOutcome( String name ){
TreeSet result= new TreeSet();
for( Iterator i = all_outcomes.iterator(); i.hasNext(); ) {
Outcome oc= i.next();
if( oc.name.contains(name) ) {result.add( oc );}
}
return result.first();
}
public void addOutcome(int bin, Outcome outcome) {
all_outcomes.add(outcome);
this.bins.elementAt(bin).add(outcome);
}
}
class Bet {
public int amountBet;
public Outcome outcome;
public Bet(int amount, Outcome outcome) {
this.outcome = outcome;
this.amountBet = amount;
}
public int winAmount() {
int winAmount = this.outcome.odds * this.amountBet;
return winAmount + this.amountBet;
}
public int loseAmount() {
int loseAmount = this.amountBet;
return loseAmount;
}
public String toString() {
return this.amountBet+" on "+"["+this.outcome.toString()+"]";
}
}
class Bin {
public TreeSet outcomes;
int i =0;
Bin(){
outcomes = new TreeSet();
}
Bin(Outcome[] outcomes){
this();
for(Outcome anOutcome: outcomes){
add(anOutcome);
}
}
Bin(Collection outcomes){
this();
for(Outcome anOutcome: outcomes){
add(anOutcome);
}
}
void add(Outcome outcome){
this.outcomes.add(outcome);
}
public String toString(){
String string ="";
Iterator it1 =this.outcomes.iterator();
while(it1.hasNext()){
string += "["+it1.next().toString()+"]";
}
return string;
}
}
class BinBuilder {
public Wheel wheel;
public NonRandom nrng;
public BinBuilder() {
this.nrng = new NonRandom();
this.wheel = new Wheel(nrng);
buildBins(wheel);
}
public Wheel getWheel() {
return wheel;
}
private void buildBins(Wheel wheel){
straightBets(wheel);
splitBets(wheel);
streetBets(wheel);
cornerBets(wheel);
lineBets(wheel);
dozenBets(wheel);
columnBets(wheel);
evenMoneyBets(wheel);
}
void straightBets(Wheel wheel){
for(int i = 1; i<37; i++){
Outcome outcome = new Outcome(""+i, 35);
String u = ""+i;
wheel.addOutcome(i , outcome);
}
}
void splitBets(Wheel wheel){
for(int r = 0; r<12; r++){
int n = (3*r) +1;
Outcome outcome = new Outcome("'"+n+", "+n+1+"'", 17);
wheel.addOutcome(n , outcome);
wheel.addOutcome(n+1 , outcome);
n = (3*r) +2;
Outcome outcome2 = new Outcome("'"+n+", "+n+1+"'", 17);
wheel.addOutcome(n , outcome2);
wheel.addOutcome(n+1, outcome2);
}
for(int n = 1; n<34; n++){
Outcome outcomen = new Outcome(n+", "+n+3, 17);
wheel.addOutcome(n , outcomen);
wheel.addOutcome(n+3 , outcomen);
}
}
void streetBets(Wheel wheel){
for(int r = 0; r<12; r++){
int n = (3*r) +1;
Outcome outcome = new Outcome(""+n, 11);
wheel.addOutcome(n , outcome);
wheel.addOutcome(n+1 , outcome);
wheel.addOutcome(n+2 , outcome);
}
}
void cornerBets(Wheel wheel){
for(int r = 0; r<11; r++){
int n = (3*r) +1;
Outcome outcome = new Outcome(n +", " +n +1+", " +n +3+", " +n +4, 8);
wheel.addOutcome(n , outcome);
wheel.addOutcome(n+1 , outcome);
wheel.addOutcome(n+3 , outcome);
wheel.addOutcome(n+4 , outcome);
int s = (3*r) +2;
Outcome outcome2 = new Outcome(s +", "+ s +1+", "+ s+3+", "+ s +4, 17);
wheel.addOutcome(n , outcome2);
wheel.addOutcome(n+1, outcome2);
wheel.addOutcome(n+3, outcome2);
wheel.addOutcome(n+4, outcome2);
}
}
void lineBets(Wheel wheel){
for(int r = 0; r<10; r++){
int n = (3*r) +1;
Outcome outcome = new Outcome(n+", "+ (n +1)+","+ (n +2)+", "+ (n +3)+", "+ (n
+4)+", "+ (n +5), 5);
wheel.addOutcome(n , outcome);
wheel.addOutcome(n+1 , outcome);
wheel.addOutcome(n+2 , outcome);
wheel.addOutcome(n+3 , outcome);
wheel.addOutcome(n+4 , outcome);
wheel.addOutcome(n+5 , outcome);
}
}
void dozenBets(Wheel wheel){
for(int d = 0; d<3; d++){
Outcome outcome = new Outcome(""+(d+1), 2);
for(int m = 0; m<12; m++){
wheel.addOutcome(12*d+m+1 , outcome);
}
}
}
void columnBets(Wheel wheel){
for(int c = 0; c<3; c++){
Outcome outcome = new Outcome(""+c+1,2);
for(int r = 0; r<12; r++){
wheel.addOutcome((3*r)+c+1 , outcome);
}
}
}
void evenMoneyBets(Wheel wheel){
for(int n = 0; n<37; n++){
if(n>=1 && n<19){
Outcome outcome_l = new Outcome("Low",1);
wheel.addOutcome(n , outcome_l);
}
else {
Outcome outcome_h = new Outcome("High",1);
wheel.addOutcome(n , outcome_h);
}
if(n%2==0){
Outcome outcome_e = new Outcome("Even",1);
wheel.addOutcome(n , outcome_e);
}
else {
Outcome outcome_o = new Outcome("Odd",1);
wheel.addOutcome(n , outcome_o);
}
int[] Red = {1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36};
if (Arrays.binarySearch(Red, n) >= 0){
Outcome outcome_r = new Outcome("Red",1);
wheel.addOutcome(n , outcome_r);
}
else {
Outcome outcome_b = new Outcome("Black",1);
wheel.addOutcome(n , outcome_b);
}
}
}
}
class NonRandom {
private long value;
public void NonRandom(){
value = 0;
}
public int next(int bits) {
return (int) value;
}
public void setSeed(long value) {
this.value = value;
}
}
------------------------------------------------output-----------------------------------------------------
[8 (35:1)]['7, 71' (17:1)]['8, 81' (17:1)][5, 53 (17:1)][8, 83 (17:1)][7 (11:1)][4, 41, 43, 44
(8:1)][5, 51, 53, 54 (17:1)][7, 71, 73, 74 (8:1)][8, 81, 83, 84 (17:1)][4, 5,6, 7, 8, 9 (5:1)][7, 8,9,
10, 11, 12 (5:1)][1 (2:1)][11 (2:1)][Low (1:1)][Even (1:1)][Black (1:1)]
[10 on [Black (35:1)]]
Black (35:1)
Black (35:1)
8 (35:1)
Win :/
'7, 71' (17:1)
Win :/
'8, 81' (17:1)
Win :/
5, 53 (17:1)
Win :/
8, 83 (17:1)
Win :/
7 (11:1)
Win :/
4, 41, 43, 44 (8:1)
Win :/
5, 51, 53, 54 (17:1)
Win :/
7, 71, 73, 74 (8:1)
Win :/
8, 81, 83, 84 (17:1)
Win :/
4, 5,6, 7, 8, 9 (5:1)
Win :/
7, 8,9, 10, 11, 12 (5:1)
Win :/
1 (2:1)
Win :/
11 (2:1)
Win :/
Low (1:1)
Win :/
Even (1:1)
Win :/
Black (1:1)
Win!

More Related Content

PDF
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
DOCX
java experiments and programs
DOCX
Java Program
PDF
in this assignment you are asked to write a simple driver program an.pdf
PDF
81818088 isc-class-xii-computer-science-project-java-programs
PDF
Let’s talk about microbenchmarking
PDF
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
PDF
C++ normal assignments by maharshi_jd.pdf
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
java experiments and programs
Java Program
in this assignment you are asked to write a simple driver program an.pdf
81818088 isc-class-xii-computer-science-project-java-programs
Let’s talk about microbenchmarking
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
C++ normal assignments by maharshi_jd.pdf

Similar to I dont know what is wrong with this roulette program I cant seem.pdf (20)

PPT
Parameters
PDF
ES6 patterns in the wild
PDF
Simple Java Program for beginner with easy method.pdf
PDF
OrderTest.javapublic class OrderTest {       Get an arra.pdf
PDF
The main class of the tictoe game looks like.public class Main {.pdf
PDF
Java programs
PDF
public interface Game Note interface in place of class { .pdf
PDF
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
DOC
PPT
Whats new in_csharp4
PPTX
Academy PRO: ES2015
DOC
5 Rmi Print
PDF
Redux saga: managing your side effects. Also: generators in es6
DOCX
Wap to implement bitwise operators
PDF
Simple 27 Java Program on basic java syntax
DOCX
C# labprograms
PDF
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
PDF
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
PDF
Given the following codepackage data1;import java.util.;p.pdf
DOCX
.net progrmming part2
Parameters
ES6 patterns in the wild
Simple Java Program for beginner with easy method.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
The main class of the tictoe game looks like.public class Main {.pdf
Java programs
public interface Game Note interface in place of class { .pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
Whats new in_csharp4
Academy PRO: ES2015
5 Rmi Print
Redux saga: managing your side effects. Also: generators in es6
Wap to implement bitwise operators
Simple 27 Java Program on basic java syntax
C# labprograms
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Given the following codepackage data1;import java.util.;p.pdf
.net progrmming part2
Ad

More from archanaemporium (20)

PDF
Identify a article about a communicable or noncommunicable disease i.pdf
PDF
i safari File Edit View History Bookmarks Window Help 67 D. Thu 101.pdf
PDF
I know that water molecules attract each other, but why do water mol.pdf
PDF
How can Internet technologies be involved in improving a process in .pdf
PDF
How many paths are there in a tree with n nodesHow many paths a.pdf
PDF
Hypothesize a way for a virus to evade a host defense & then devise .pdf
PDF
How many ways can letters of the word SINGAPORE be arranged such that.pdf
PDF
Haploid. After is complete, the resulting gametes are haploid. This m.pdf
PDF
FTP and TFTP are primarily file transfer protocols. What is the main.pdf
PDF
Given Starter Fileimport java.util.Arrays; Encapsulates.pdf
PDF
Express the verbal representation for the function f symbolically. M.pdf
PDF
Economic resources have a price above zero because...A. there are .pdf
PDF
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf
PDF
Discuss in detail how two different Progressive reformers tackled th.pdf
PDF
Describe the major parts of the nervous system and their functions..pdf
PDF
DEFINE gene enhancer and gene promoter (3-4 sentences each).Sol.pdf
PDF
Cisco Systems, Inc. offers a switching technology known as Multi-Lay.pdf
PDF
C# ProgramingHow a derived class that inherits attributes and beha.pdf
PDF
Assume that x and y are already defined as being of type int . Write.pdf
PDF
Briefly define cyberterrorism. Define hacktivism. Illustrate example.pdf
Identify a article about a communicable or noncommunicable disease i.pdf
i safari File Edit View History Bookmarks Window Help 67 D. Thu 101.pdf
I know that water molecules attract each other, but why do water mol.pdf
How can Internet technologies be involved in improving a process in .pdf
How many paths are there in a tree with n nodesHow many paths a.pdf
Hypothesize a way for a virus to evade a host defense & then devise .pdf
How many ways can letters of the word SINGAPORE be arranged such that.pdf
Haploid. After is complete, the resulting gametes are haploid. This m.pdf
FTP and TFTP are primarily file transfer protocols. What is the main.pdf
Given Starter Fileimport java.util.Arrays; Encapsulates.pdf
Express the verbal representation for the function f symbolically. M.pdf
Economic resources have a price above zero because...A. there are .pdf
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf
Discuss in detail how two different Progressive reformers tackled th.pdf
Describe the major parts of the nervous system and their functions..pdf
DEFINE gene enhancer and gene promoter (3-4 sentences each).Sol.pdf
Cisco Systems, Inc. offers a switching technology known as Multi-Lay.pdf
C# ProgramingHow a derived class that inherits attributes and beha.pdf
Assume that x and y are already defined as being of type int . Write.pdf
Briefly define cyberterrorism. Define hacktivism. Illustrate example.pdf
Ad

Recently uploaded (20)

DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Computer Architecture Input Output Memory.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
HVAC Specification 2024 according to central public works department
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
1_English_Language_Set_2.pdf probationary
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Virtual and Augmented Reality in Current Scenario
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
IGGE1 Understanding the Self1234567891011
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Computer Architecture Input Output Memory.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Indian roads congress 037 - 2012 Flexible pavement
HVAC Specification 2024 according to central public works department
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
A powerpoint presentation on the Revised K-10 Science Shaping Paper
202450812 BayCHI UCSC-SV 20250812 v17.pptx
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
1_English_Language_Set_2.pdf probationary
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Virtual and Augmented Reality in Current Scenario
Introduction to pro and eukaryotes and differences.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
IGGE1 Understanding the Self1234567891011
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
FORM 1 BIOLOGY MIND MAPS and their schemes

I dont know what is wrong with this roulette program I cant seem.pdf

  • 1. I don't know what is wrong with this roulette program I can't seem to get it to run. Game Class: public class Game { public static void main(String[] args) { Table table = new Table(); BinBuilder bb = new BinBuilder(); Outcome black = new Outcome("Black", 35); Bet bet = new Bet(10, black); table.placeBet(bet); Bin bin = bb.wheel.get(8); System.out.println(bin.toString()); System.out.println(table.bets.toString()); System.out.println(black.toString()); ListIterator i = table.bets.listIterator(); Iterator b = bin.outcomes.iterator(); while(i.hasNext()) { System.out.println(i.next().outcome.name.toString()); while(b.hasNext()){ System.out.println(b.next().name.toString()); if(i.next().outcome.equals(b.next())){ System.out.println("Win!"); } else{ System.out.println("Win :/"); } } } } }
  • 2. Player Class public class Player { public Table table; public Outcome black; public Bet bet; public Player(Table table) { table = new Table(); black = new Outcome("Black", 1); } void placeBets() { Bet bet = new Bet(100, black); table.placeBet(bet); } void win(Bet bet) { System.out.println("You've won: " + bet.winAmount()); } void lose(Bet bet) { System.out.println("You lost!" + bet.loseAmount() + ":/"); } } Outcome class public class Outcome implements Comparable { public String name; public int odds; public Outcome(String name, int odds){ this.name = name; this.odds = odds; } public int winAmount(int amount){
  • 3. return amount*this.odds; } public boolean equals(Outcome other){ return (this.name.equals(other.name)); } public String toString() { Object[] values= { name, new Integer(odds) }; String msgTempl= "{0} ({1}:1)"; return MessageFormat.format( msgTempl, values ); } @Override public int compareTo(E arg0) { if(this.equals(arg0)){ return 0; } return 1; } } Table Class public class Table { public int limit = 1000; public LinkedList bets; public Table() { bets = new LinkedList(); } public boolean isValid(Bet bet) { int sum = 0; for(Bet bett: bets) { sum += bett.amountBet; } return (sum>limit);
  • 4. } public void placeBet(Bet bet) { bets.add(bet); } ListIterator iterator() { return bets.listIterator(); } } Wheel Class public class Wheel extends TreeSet { Vector bins; NonRandom rng; Set all_outcomes; Wheel(NonRandom rng){ this.rng = rng; rng = new NonRandom(); all_outcomes = new TreeSet(); bins = new Vector(38); for (int i=0; i<38; i++){ bins.add(i, new Bin()); } } Bin next(){ int rand = rng.next(38); return bins.elementAt(rand); } Bin get(int bin){ return bins.elementAt(bin);
  • 5. } public Outcome getOutcome( String name ){ TreeSet result= new TreeSet(); for( Iterator i = all_outcomes.iterator(); i.hasNext(); ) { Outcome oc= i.next(); if( oc.name.contains(name) ) {result.add( oc );} } return result.first(); } public void addOutcome(int bin, Outcome outcome) { all_outcomes.add(outcome); this.bins.elementAt(bin).add(outcome); } } Bet Class public class Bet { public int amountBet; public Outcome outcome; public Bet(int amount, Outcome outcome) { this.outcome = outcome; this.amountBet = amount; } public int winAmount() { int winAmount = this.outcome.odds * this.amountBet; return winAmount + this.amountBet; } public int loseAmount() { int loseAmount = this.amountBet; return loseAmount;
  • 6. } public String toString() { return this.amountBet+" on "+"["+this.outcome.toString()+"]"; } } Bin Class public class Bin { public TreeSet outcomes; int i =0; Bin(){ outcomes = new TreeSet(); } Bin(Outcome[] outcomes){ this(); for(Outcome anOutcome: outcomes){ add(anOutcome); } } Bin(Collection outcomes){ this(); for(Outcome anOutcome: outcomes){ add(anOutcome); } } void add(Outcome outcome){ this.outcomes.add(outcome); } public String toString(){ String string =""; Iterator it1 =this.outcomes.iterator(); while(it1.hasNext()){ string += "["+it1.next().toString()+"]";
  • 7. } return string; } } BinBuilder Class public class BinBuilder { public Wheel wheel; public NonRandom nrng; public BinBuilder() { this.nrng = new NonRandom(); this.wheel = new Wheel(nrng); buildBins(wheel); } public Wheel getWheel() { return wheel; } private void buildBins(Wheel wheel){ straightBets(wheel); splitBets(wheel); streetBets(wheel); cornerBets(wheel); lineBets(wheel); dozenBets(wheel); columnBets(wheel); evenMoneyBets(wheel); } void straightBets(Wheel wheel){ for(int i = 1; i<37; i++){ Outcome outcome = new Outcome(""+i, 35); String u = ""+i; wheel.addOutcome(i , outcome); } } void splitBets(Wheel wheel){ for(int r = 0; r<12; r++){
  • 8. int n = (3*r) +1; Outcome outcome = new Outcome("'"+n+", "+n+1+"'", 17); wheel.addOutcome(n , outcome); wheel.addOutcome(n+1 , outcome); n = (3*r) +2; Outcome outcome2 = new Outcome("'"+n+", "+n+1+"'", 17); wheel.addOutcome(n , outcome2); wheel.addOutcome(n+1, outcome2); } for(int n = 1; n<34; n++){ Outcome outcomen = new Outcome(n+", "+n+3, 17); wheel.addOutcome(n , outcomen); wheel.addOutcome(n+3 , outcomen); } } void streetBets(Wheel wheel){ for(int r = 0; r<12; r++){ int n = (3*r) +1; Outcome outcome = new Outcome(""+n, 11); wheel.addOutcome(n , outcome); wheel.addOutcome(n+1 , outcome); wheel.addOutcome(n+2 , outcome); } } void cornerBets(Wheel wheel){ for(int r = 0; r<11; r++){ int n = (3*r) +1; Outcome outcome = new Outcome(n +", " +n +1+", " +n +3+", " +n +4, 8); wheel.addOutcome(n , outcome); wheel.addOutcome(n+1 , outcome); wheel.addOutcome(n+3 , outcome); wheel.addOutcome(n+4 , outcome); int s = (3*r) +2; Outcome outcome2 = new Outcome(s +", "+ s +1+", "+ s+3+", "+ s +4, 17); wheel.addOutcome(n , outcome2); wheel.addOutcome(n+1, outcome2);
  • 9. wheel.addOutcome(n+3, outcome2); wheel.addOutcome(n+4, outcome2); } } void lineBets(Wheel wheel){ for(int r = 0; r<10; r++){ int n = (3*r) +1; Outcome outcome = new Outcome(n+", "+ (n +1)+","+ (n +2)+", "+ (n +3)+", "+ (n +4)+", "+ (n +5), 5); wheel.addOutcome(n , outcome); wheel.addOutcome(n+1 , outcome); wheel.addOutcome(n+2 , outcome); wheel.addOutcome(n+3 , outcome); wheel.addOutcome(n+4 , outcome); wheel.addOutcome(n+5 , outcome); } } void dozenBets(Wheel wheel){ for(int d = 0; d<3; d++){ Outcome outcome = new Outcome(""+(d+1), 2); for(int m = 0; m<12; m++){ wheel.addOutcome(12*d+m+1 , outcome); } } } void columnBets(Wheel wheel){ for(int c = 0; c<3; c++){ Outcome outcome = new Outcome(""+c+1,2); for(int r = 0; r<12; r++){ wheel.addOutcome((3*r)+c+1 , outcome); } } } void evenMoneyBets(Wheel wheel){ for(int n = 0; n<37; n++){ if(n>=1 && n<19){
  • 10. Outcome outcome_l = new Outcome("Low",1); wheel.addOutcome(n , outcome_l); } else { Outcome outcome_h = new Outcome("High",1); wheel.addOutcome(n , outcome_h); } if(n%2==0){ Outcome outcome_e = new Outcome("Even",1); wheel.addOutcome(n , outcome_e); } else { Outcome outcome_o = new Outcome("Odd",1); wheel.addOutcome(n , outcome_o); } int[] Red = {1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36}; if (Arrays.binarySearch(Red, n) >= 0){ Outcome outcome_r = new Outcome("Red",1); wheel.addOutcome(n , outcome_r); } else { Outcome outcome_b = new Outcome("Black",1); wheel.addOutcome(n , outcome_b); } } } } NonRandom Class public class NonRandom { private long value; public void NonRandom(){ value = 0; } public int next(int bits) { return (int) value;
  • 11. } public void setSeed(long value) { this.value = value; } } Solution In the main method you are calling the i.next() and b.next() method twice in a loop which cause an error. I have made the changes. Kindly go through the changes that i have made. ------------------------------------------------code-------------------------------------------------------------- --------------------------------- import java.text.MessageFormat; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.ListIterator; import java.util.Set; import java.util.TreeSet; import java.util.Vector; import java.util.LinkedList; public class Game { public static void main(String[] args) { Table table = new Table(); BinBuilder bb = new BinBuilder(); Outcome black = new Outcome("Black", 35); Bet bet = new Bet(10, black); table.placeBet(bet); Bin bin = bb.wheel.get(8); System.out.println(bin.toString()); System.out.println(table.bets.toString()); System.out.println(black.toString());
  • 12. ListIterator i = table.bets.listIterator(); Iterator b = bin.outcomes.iterator(); while(i.hasNext()) { Outcome outcome=i.next().outcome; System.out.println(outcome); while(b.hasNext()){ Outcome binOutcome=b.next(); System.out.println(binOutcome); if(outcome.equals(binOutcome)){ System.out.println("Win!"); } else{ System.out.println("Win :/"); } } } } } class Player { public Table table; public Outcome black; public Bet bet; public Player(Table table) { table = new Table(); black = new Outcome("Black", 1); } void placeBets() { Bet bet = new Bet(100, black); table.placeBet(bet); }
  • 13. void win(Bet bet) { System.out.println("You've won: " + bet.winAmount()); } void lose(Bet bet) { System.out.println("You lost!" + bet.loseAmount() + ":/"); } } class Outcome implements Comparable { public String name; public int odds; public Outcome(String name, int odds){ this.name = name; this.odds = odds; } public int winAmount(int amount){ return amount*this.odds; } public boolean equals(Outcome other){ return (this.name.equals(other.name)); } public String toString() { Object[] values= { name, new Integer(odds) }; String msgTempl= "{0} ({1}:1)"; return MessageFormat.format( msgTempl, values ); } @Override public int compareTo(E arg0) { if(this.equals(arg0)){
  • 14. return 0; } return 1; } } class Table { public int limit = 1000; public LinkedListbets; public Table() { bets = new LinkedList(); } public boolean isValid(Bet bet) { int sum = 0; for(Bet bett: bets) { sum += bett.amountBet; } return (sum>limit); } public void placeBet(Bet bet) { bets.add(bet); } ListIterator iterator() { return bets.listIterator(); } } class Wheel extends TreeSet { Vector bins; NonRandom rng; Set all_outcomes;
  • 15. Wheel(NonRandom rng){ this.rng = rng; rng = new NonRandom(); all_outcomes = new TreeSet(); bins = new Vector(38); for (int i=0; i<38; i++){ bins.add(i, new Bin()); } } Bin next(){ int rand = rng.next(38); return bins.elementAt(rand); } Bin get(int bin){ return bins.elementAt(bin); } public Outcome getOutcome( String name ){ TreeSet result= new TreeSet(); for( Iterator i = all_outcomes.iterator(); i.hasNext(); ) { Outcome oc= i.next(); if( oc.name.contains(name) ) {result.add( oc );} } return result.first(); } public void addOutcome(int bin, Outcome outcome) { all_outcomes.add(outcome); this.bins.elementAt(bin).add(outcome);
  • 16. } } class Bet { public int amountBet; public Outcome outcome; public Bet(int amount, Outcome outcome) { this.outcome = outcome; this.amountBet = amount; } public int winAmount() { int winAmount = this.outcome.odds * this.amountBet; return winAmount + this.amountBet; } public int loseAmount() { int loseAmount = this.amountBet; return loseAmount; } public String toString() { return this.amountBet+" on "+"["+this.outcome.toString()+"]"; } } class Bin { public TreeSet outcomes; int i =0; Bin(){ outcomes = new TreeSet(); }
  • 17. Bin(Outcome[] outcomes){ this(); for(Outcome anOutcome: outcomes){ add(anOutcome); } } Bin(Collection outcomes){ this(); for(Outcome anOutcome: outcomes){ add(anOutcome); } } void add(Outcome outcome){ this.outcomes.add(outcome); } public String toString(){ String string =""; Iterator it1 =this.outcomes.iterator(); while(it1.hasNext()){ string += "["+it1.next().toString()+"]"; } return string; } } class BinBuilder { public Wheel wheel; public NonRandom nrng; public BinBuilder() {
  • 18. this.nrng = new NonRandom(); this.wheel = new Wheel(nrng); buildBins(wheel); } public Wheel getWheel() { return wheel; } private void buildBins(Wheel wheel){ straightBets(wheel); splitBets(wheel); streetBets(wheel); cornerBets(wheel); lineBets(wheel); dozenBets(wheel); columnBets(wheel); evenMoneyBets(wheel); } void straightBets(Wheel wheel){ for(int i = 1; i<37; i++){ Outcome outcome = new Outcome(""+i, 35); String u = ""+i; wheel.addOutcome(i , outcome); } } void splitBets(Wheel wheel){ for(int r = 0; r<12; r++){ int n = (3*r) +1; Outcome outcome = new Outcome("'"+n+", "+n+1+"'", 17); wheel.addOutcome(n , outcome); wheel.addOutcome(n+1 , outcome);
  • 19. n = (3*r) +2; Outcome outcome2 = new Outcome("'"+n+", "+n+1+"'", 17); wheel.addOutcome(n , outcome2); wheel.addOutcome(n+1, outcome2); } for(int n = 1; n<34; n++){ Outcome outcomen = new Outcome(n+", "+n+3, 17); wheel.addOutcome(n , outcomen); wheel.addOutcome(n+3 , outcomen); } } void streetBets(Wheel wheel){ for(int r = 0; r<12; r++){ int n = (3*r) +1; Outcome outcome = new Outcome(""+n, 11); wheel.addOutcome(n , outcome); wheel.addOutcome(n+1 , outcome); wheel.addOutcome(n+2 , outcome); } } void cornerBets(Wheel wheel){ for(int r = 0; r<11; r++){ int n = (3*r) +1; Outcome outcome = new Outcome(n +", " +n +1+", " +n +3+", " +n +4, 8); wheel.addOutcome(n , outcome); wheel.addOutcome(n+1 , outcome); wheel.addOutcome(n+3 , outcome);
  • 20. wheel.addOutcome(n+4 , outcome); int s = (3*r) +2; Outcome outcome2 = new Outcome(s +", "+ s +1+", "+ s+3+", "+ s +4, 17); wheel.addOutcome(n , outcome2); wheel.addOutcome(n+1, outcome2); wheel.addOutcome(n+3, outcome2); wheel.addOutcome(n+4, outcome2); } } void lineBets(Wheel wheel){ for(int r = 0; r<10; r++){ int n = (3*r) +1; Outcome outcome = new Outcome(n+", "+ (n +1)+","+ (n +2)+", "+ (n +3)+", "+ (n +4)+", "+ (n +5), 5); wheel.addOutcome(n , outcome); wheel.addOutcome(n+1 , outcome); wheel.addOutcome(n+2 , outcome); wheel.addOutcome(n+3 , outcome); wheel.addOutcome(n+4 , outcome); wheel.addOutcome(n+5 , outcome); } } void dozenBets(Wheel wheel){ for(int d = 0; d<3; d++){ Outcome outcome = new Outcome(""+(d+1), 2); for(int m = 0; m<12; m++){ wheel.addOutcome(12*d+m+1 , outcome); } } }
  • 21. void columnBets(Wheel wheel){ for(int c = 0; c<3; c++){ Outcome outcome = new Outcome(""+c+1,2); for(int r = 0; r<12; r++){ wheel.addOutcome((3*r)+c+1 , outcome); } } } void evenMoneyBets(Wheel wheel){ for(int n = 0; n<37; n++){ if(n>=1 && n<19){ Outcome outcome_l = new Outcome("Low",1); wheel.addOutcome(n , outcome_l); } else { Outcome outcome_h = new Outcome("High",1); wheel.addOutcome(n , outcome_h); } if(n%2==0){ Outcome outcome_e = new Outcome("Even",1); wheel.addOutcome(n , outcome_e); } else { Outcome outcome_o = new Outcome("Odd",1); wheel.addOutcome(n , outcome_o); } int[] Red = {1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36};
  • 22. if (Arrays.binarySearch(Red, n) >= 0){ Outcome outcome_r = new Outcome("Red",1); wheel.addOutcome(n , outcome_r); } else { Outcome outcome_b = new Outcome("Black",1); wheel.addOutcome(n , outcome_b); } } } } class NonRandom { private long value; public void NonRandom(){ value = 0; } public int next(int bits) { return (int) value; } public void setSeed(long value) { this.value = value; } } ------------------------------------------------output----------------------------------------------------- [8 (35:1)]['7, 71' (17:1)]['8, 81' (17:1)][5, 53 (17:1)][8, 83 (17:1)][7 (11:1)][4, 41, 43, 44 (8:1)][5, 51, 53, 54 (17:1)][7, 71, 73, 74 (8:1)][8, 81, 83, 84 (17:1)][4, 5,6, 7, 8, 9 (5:1)][7, 8,9, 10, 11, 12 (5:1)][1 (2:1)][11 (2:1)][Low (1:1)][Even (1:1)][Black (1:1)] [10 on [Black (35:1)]] Black (35:1) Black (35:1) 8 (35:1) Win :/ '7, 71' (17:1)
  • 23. Win :/ '8, 81' (17:1) Win :/ 5, 53 (17:1) Win :/ 8, 83 (17:1) Win :/ 7 (11:1) Win :/ 4, 41, 43, 44 (8:1) Win :/ 5, 51, 53, 54 (17:1) Win :/ 7, 71, 73, 74 (8:1) Win :/ 8, 81, 83, 84 (17:1) Win :/ 4, 5,6, 7, 8, 9 (5:1) Win :/ 7, 8,9, 10, 11, 12 (5:1) Win :/ 1 (2:1) Win :/ 11 (2:1) Win :/ Low (1:1) Win :/ Even (1:1) Win :/ Black (1:1) Win!