好吧,所以我必须写一个类和驱动程序,用户输入的骰子数和掷骰数。然后我必须根据骰子的数量* 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