Please help me
/**Die.java*/
import java.util.*;
public class Die
{
private int sides;
private final int s = 6; //maximum face value
private int valueOnDie; // current value showing on the die
// Constructor which sets the initial face value
public Die()
{
valueOnDie = 1;
}
public Die(int s)
{
sides = s;
}
public int roll()
{
valueOnDie = (int)(Math.random() * s) + 1;
return valueOnDie;
}
public void setValue (int value)
{
valueOnDie = value;
}
public int getValue()
{
return valueOnDie;
}
public String toString()
{
String result = Integer.toString(valueOnDie);
return result;
}
}
/**PairOfDice.java*/
import java.util.*;
import java.text.*;
import java.io.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class PairOfDice //extends JFrame
{
private Die die1, die2;
int value1,value2,total;
public PairOfDice ()
{
die1 = new Die();
die2 = new Die();
}
public int roll ()
{
value1 = die1.roll();
value2 = die2.roll();
total = value1 + value2;
return total;
}
public int getDie1()
{
return die1.getValue();
}
public int getDie2()
{
return die2.getValue();
}
public int getSum ()
{
return (die1.getValue()+die2.getValue());
}
}
/**DiceRoller.java*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DiceRoller extends JFrame{
private JTextField firstDie = new JTextField(3);
private JTextField secondDie = new JTextField(3);
private JTextField totalRoll = new JTextField(3);
public DiceRoller()
{
JButton rollBtn= new JButton("Roll");
rollBtn.addActionListener(new RollBtnListener());
JButton exitBtn = new JButton("Exit");
exitBtn.addActionListener(new ExitBtnListener());
JPanel content = new JPanel();
content.setLayout(new FlowLayout());
content.add(new JLabel("First Die:"));
content.add(firstDie);
content.add(new JLabel("Second Die:"));
content.add(secondDie);
content.add(new JLabel("Total roll:"));
content.add(totalRoll);
content.add(rollBtn);
content.add(exitBtn);
setContentPane(content);
pack();
setTitle("Dice Roller");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class RollBtnListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int t,d1,d2;
PairOfDice frm = new PairOfDice();
t=frm.roll();
d1 = frm.getDie1();
d2 = frm.getDie2();
System.out.println("Sum of Dice:"+t);
System.out.println("Die1:"+d1);
System.out.println("Die2:"+d2);
/*if(t == 7)
System.out.println("Craps!");
if(d1==d2)
{
if(d1==1)
System.out.println("Snake Eyes!");
else if(d1==6)
System.out.println("Box Cars!");
}
*/
totalRoll.setText(""+t);
firstDie.setText(""+d1);
secondDie.setText(""+d2);
}
}
class ExitBtnListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main(String args[]){
DiceRoller window = new DiceRoller();
window.setVisible(true);
}
}
there is no problem with the code that i had given above it is working perfectly
i wanted to add some statements in the DiceRoller.java that if the dice is rolled and if both the die1 and die2 are 1 it should show the message "snake Eyes"
and if die1=die2=6 it should show Box cars
and if the total of the dice is 7 then it should show Craps!
so how can i add these features into my original program
my original program output is as shown
Dice Roller(title)
First Die: 6Second Die: 1Total roll: 7Roll(button)Exit(button)
since the total is 7 it should display the message Craps! in the window
please help me i will be thankful to you

