java - Slot machine program -



java - Slot machine program -

hey trying programme game simulates slot machine , implements interface game 3 methods

public string getprize(); public string equipmentneeded(); public string rules();

i thought had created game isnt compiling , neither eclipse or current knowledge on java syntax showing problem. code far:

public class slotmachine implements game { private double balance=15; private boolean enoughmoney, won=false; public string getprize() { string s=""+balance; homecoming s; } public string equipmentneeded() { if(balance<5){ enoughmoney=false; homecoming "you need more money."; } else enoughmoney=true; homecoming "good luck... game definetely isn't rigged"; } public string rules() { homecoming "the game costs 5 cents play. if win, 10 cents. start game must pull lever spins wheels. if 3 out of 5 wheels have cherries , remaining wheels aren't lemons win!"; } public boolean pulllever(){ if(enoughmoney) homecoming true; else{ system.out.println("you have "+balance+". need @ to the lowest degree 5 play"); homecoming false; } } public void playgame(){ string choices[]={"cherries", "oranges", "lemons", "wild card", "bananas"}; string guess[]=new string[5]; balance=balance-5; if(pulllever()){ for(int i=0; i<choices.length; i++){ guess[i]=choices[(int)(math.random()*6)]; } for(int x=0; x<guess.length-2; x++){ if(guess[x].equals("cherries")==false){ system.out.println(guess[x]); won=false; } else for(int w=4; w<=5; w++){ if(guess[w].equals("lemons")){ won=false; system.out.println("guess[w]"); } else won=true; } } } if(won=true){ balance=balance+10; system.out.println("you have won!"); } else system.out.println("try again!"); } }

i agree comment there error message you're missing (eclipse pretty marking straight of box). however, that's different issue (although 1 should set effort solving).

in playgame() have next line:

if(won=true){

the problem utilize single =, meaning assignment. want double == comparison. cannot assign value within of if condition. , that's what's causing error.

x = 2; //assigns value of 2 x. x == 2; //compares value 2 x. value of x not change. returns boolean.

note == compares references fine applications certian datatypes strings should se string.equals().

java eclipse oop syntax

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -