-3
나는 슬롯 머신을 시뮬레이션하고 내가 성공적으로 게임을 만들었다 고 생각하는 세 가지 방법슬롯 머신 프로그램
public String getPrize();
public String equipmentNeeded();
public String rules();
와 인터페이스 게임을 구현하는 게임을 프로그래밍하려고하지만 컴파일 밤은 어느 쪽도 아니 일식 이봐 나 자바 구문에 대한 나의 현재 지식은 문제를 보여주고있다. (이클립스 상자의 직선을 그 마크 업에 대한 아주 좋은) 당신이 놓치고있는 오류 메시지가 아마도이 있음을
public class SlotMachine implements Game {
private double Balance=15;
private boolean enoughMoney, won=false;
public String getPrize() {
String s=""+Balance;
return s;
}
public String equipmentNeeded() {
if(Balance<5){
enoughMoney=false;
return "You need more money.";
}
else
enoughMoney=true;
return "Good luck... the game definetely isn't rigged";
}
public String rules() {
return "The game costs five cents to play. If you win, you get ten cents. To start the game you must pull the lever that spins the wheels. If 3 out of the 5 wheels have cherries and the remaining wheels aren't lemons then you win!";
}
public boolean pullLever(){
if(enoughMoney)
return true;
else{
System.out.println("You have "+Balance+". You need at least five to play");
return 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!");
}
}
게임 클래스는 어디에 있습니까? –
컴파일러는 왜 컴파일하지 않는지에 대해 __very__를 잘 알고 있습니다. 어딘가에 메시지가 있습니다. 그것을 찾아서 여기에 게시하십시오. –
이것은 프로그램을 컴파일하지 않는 원인이 아니지만 브라케팅을 다시 확인해야합니다. 특히,'equipmentNeeded()'의'else' 문은 당신이 생각하는 것처럼 행동하지 않습니다. (https://stackoverflow.com/questions/8020228/is-it-ok-if-i-omit- curly-braces-in-java) – acattle