السلام عليكم ورحمة الله وبركاته ،،،
هذه محاولة قمت فيها لتصميم برنامج يقوم برمي 5 ازهار من النرد بشكل عشوائي
انا متأكد من ان الطريقه الي اتبعتها بدائية جدا لكن هي محاوله
ارجوا من الاخوان الخبراء في الجافا يبدون وجهة نظرهم في الكود
وكيفية تطويره اذا كان يحتاج تطوير
import java.util.*;
/**
* ListofDises calss is a class that make list of dices and throw them randomy .
*
* @author (Majed)
* @version (V.1 12-10-08)
*/
public class ListofDises
{
private ArrayList<Dice> dices;
/**
* Constructor for objects of class ListofDises
*/
public ListofDises()
{
dices = new ArrayList<Dice>();
filldice();
}
/**
* private method to create a list of dices
*
*
*/
private void filldice()
{
Dice dice1 = new Dice();
Dice dice2 = new Dice();
Dice dice3 = new Dice();
Dice dice4 = new Dice();
Dice dice5 = new Dice();
dices.add(dice1);
dices.add(dice2);
dices.add(dice3);
dices.add(dice4);
dices.add(dice5);
}
/**
* iterate over the dice and throw the dice
*
*
*/
public void throwDices()
{
for(Dice dic : dices){
dic.throwDice();
}
System.out.println();
}
}
import java.util.*;
public class Dice
{
private Random dice;
/**
* Constructor for objects of class Dice
*/
public Dice()
{
// initialise instance variables
dice = new Random();
}
public void throwDice()
{
int index = dice.nextInt(6);
System.out.print(index + 1);
}
}
