好吧,所以我必須寫一個類和驅動程序,用戶輸入的骰子數和擲骰數。然後我必須根據骰子的數量* 6做出一個數組,但我會得到錯誤。像arrayindexoutofboundsexception。滾動骰子類和驅動程序
我做了數組後,我必須用隨機數填充它並使用直方圖來顯示程序。所以程序應該看起來像這樣 請給這裏任何積極的幫助,即時通訊新的編程這個,我想了解更多。還我似乎無法弄清楚,如果爲Y/N區域語句來啓動程序
Welcome to the dice-rolling simulator!
Do you wish to run a simulaton? Y/N: x
that was an invalid option. Please try again.
Do you wish to run a simulation? Y/N: y
How many dise di you wish to roll? 2
How many rolls to you wish to make? 100000
2:@@@@@@
3:@@@@
4:@@@@@@@@@@@
5:@@@@@
6:@@
7:@
8:
9:@@@@@@@@@@
10:@@@
11:@@@@@@@@@@@@@@
12:@@@@@@
//我不得不給你@符號,因爲*不會在這裏工作
這裏是我的節目更新!我如何創建直方圖?
package dice;
import java.util.Scanner;
import java.util.Random;
public class Dice
{
public static Scanner in = new Scanner (System.in);
private int dice = 0;
private int roll = 0;
private int start;
private int[] diceAr;
private int[] rollAr;
private int simDice;
private String star = "*";
//****************************************************************
public Dice()
{
System.out.println("Welcome to the dice-rolling simulator!\n");
System.out.println("Do you wish to run a simulation? Y/N; ");
//start = in.nextInt();
while (true) {
System.out.print ("How Many Dice Do You Want To Roll? ");
dice = in.nextInt();
simDice = (dice * 6)-1;
diceAr = new int[simDice];
if (dice > 0)
break;
}
while (true) {
System.out.print ("How Many Times Do You Want To Roll? ");
roll = in.nextInt();
rollAr = new int[roll];
if (roll > 0)
break;
}
}
//**********************************************
// public void display()
// {
//
for (int i = 0; i < simDice; i++)
// {
// diceAr[i] = (int)(Math.random()* simDice);
//
// }
// for(int i = 0; i<simDice; i++)
// {
// System.out.println((i + dice) + ". " + diceAr[i]);
// }
//
// }
//*********************************************************
public void display(int diceAr[], int simDice, int roll)
{
for(int i=0; i < simDice; i++)
{
diceAr[i] = (int) (Math.random()* simDice);
}
for(int i=0; i < roll; i++)
{
}
}
}
聞起來像功課,所以我添加了作業標記 – 2011-03-31 09:50:35
是的,但我問了一個很好的問題,我只是有點卡在這一點上,我想在我明天得到教授幫助之前完成儘可能多的工作 – Dakota 2011-03-31 09:54:50
沒有錯!這只是「維護」;)您還應該考慮在主函數中放置「掃描」邏輯,以便在收集所需變量後,可以通過將這些值傳遞給構造函數來實例化Dice對象類骰子。 – 2011-03-31 09:56:40