我在我的介紹類在努力前進,我已經差不多完成了我的最後一個項目,基諾。它是一種根據您與經銷商匹配的數字獎勵金錢的博彩遊戲。我在投注方面有問題,他們以100美元開始,並被要求支付一定數額的金錢。我不知道哪種方法可以繼續工作,因爲我的方法不是空洞的,所以我不能返回多個數據值。投注和搜索的唯一性
我的第二個問題,也許更重要的是,他們必須是唯一的編號。爲此,我需要每次搜索數字數組以查看它們是否匹配,或者使用布爾數組來跟蹤數字。我不知道我會怎麼做第二,但我有一個很好的想法,我會做第一次。該問題是使用DO,即時通訊,而已經,林不知道我會如何與嵌套添加for循環中循環這裏是我的代碼,對不起,如果它的凌亂,我知道我的老師不喜歡我的大括號:
package Keno;
import cs1.Keyboard;
public class Keno {
public static void main(String[]args){
int userArr[]=user();
int compArr[]=computer();
int howMany=matchNums(compArr,userArr);
int moneyGained=betting(howMany);
System.out.println("You matched "+howMany+" numbers");
System.out.println("You have gained "+moneyGained+" dollars!");
}
public static int[] computer(){
int []compChoice=new int[20];
for(int x=0;x<compChoice.length;x++){
compChoice[x]=(int)(Math.random()*81);
}
return compChoice;
}
public static int[] user(){
int choice[]=new int[7];
System.out.println("Welcome to Keno!");
System.out.println("Choose 7 unique numbers ranging from 1-80");
System.out.println("*************************************************");
//assigns numbers to choice array
for(int x=0;x<choice.length;x++){
do{
int temp=x+1;
System.out.println("number "+temp+": ");
choice[x]=Keyboard.readInt();
}while(choice[x]<0||choice[x]>80);
}
System.out.println("Thanks!");
System.out.println("*************************************************");
return choice;
}
public static int matchNums(int arr1[], int arr2[]){
int count=0;
//checks each array slot individually to see if they match
for(int x=0;x<arr1.length;x++){
for(int y=0;y<arr2.length;y++){
if(arr1[x]==arr2[y]){
count++;
}
}
}
return count;
}
public static int betting(int matches){
int moneyGained=0;
if(matches==7){
moneyGained=12000;
}else if(matches==6){
moneyGained=200;
}else if(matches==5){
moneyGained=20;
}else if(moneyGained==4){
moneyGained=1;
}
return moneyGained;
}
}
對於第一個問題,何談創造,將保持當前的資金跟蹤變量並編寫返回金錢的用戶已決定工資額的方法? (然後可以用來更新您的初始變量) – 2013-04-20 13:40:02
或者使用ArrayList和檢查。載有(數字) – arynaq 2013-04-20 14:00:51