I dont know what is wrong with this roulette program I cant

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<Bet> i = table.bets.listIterator();

       Iterator<Outcome> 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<E> implements Comparable<E> {

   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<E> 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<Bet> bets;

  

       public Table() {

           bets = new LinkedList<Bet>();

   }

  

   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<Bet> iterator() {

       return bets.listIterator();

   }

}

Wheel Class

public class Wheel extends TreeSet {

   Vector<Bin> bins;

   NonRandom rng;

   Set<Outcome> all_outcomes;

  

   Wheel(NonRandom rng){

       this.rng = rng;

       rng = new NonRandom();

       all_outcomes = new TreeSet<Outcome>();

      

       bins = new Vector<Bin>(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<Outcome> result= new TreeSet<Outcome>();

for( Iterator<Outcome> 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<Outcome> outcomes;

   int i =0;

   Bin(){

       outcomes = new TreeSet<Outcome>();

   }

   Bin(Outcome[] outcomes){

       this();

       for(Outcome anOutcome: outcomes){

           add(anOutcome);

       }

   }

      

   Bin(Collection<Outcome> 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<Bet> i = table.bets.listIterator();
Iterator<Outcome> 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<E> implements Comparable<E> {

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<E> 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 LinkedList<Bet>bets;
  
public Table() {
bets = new LinkedList<Bet>();
}
  
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<Bet> iterator() {
return bets.listIterator();
}
}

class Wheel extends TreeSet {
Vector<Bin> bins;
NonRandom rng;

Set<Outcome> all_outcomes;
  
Wheel(NonRandom rng){
this.rng = rng;
rng = new NonRandom();
all_outcomes = new TreeSet<Outcome>();
  
bins = new Vector<Bin>(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<Outcome> result= new TreeSet<Outcome>();
for( Iterator<Outcome> 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<Outcome> outcomes;
int i =0;

Bin(){
outcomes = new TreeSet<Outcome>();
}
Bin(Outcome[] outcomes){
this();
for(Outcome anOutcome: outcomes){
add(anOutcome);
}
}
  
Bin(Collection<Outcome> 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!

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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site