Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Random; public class Slot { private int sides =3; public int value; public int value2; public int value3; public Slot() { roll(); } //

import java.util.Random; public class Slot { private int sides =3; public int value; public int value2; public int value3;

public Slot() {

roll();

} // Storing sides into value public void roll( ) { Random rand = new Random(); value = rand.nextInt(sides)+1; value2 = rand.nextInt(sides)+1; value3 = rand.nextInt(sides)+1;

}

public void setvalue(int Value) { value = Value; }

public void setvalue2(int Value2) { value2 = Value2; }

public void setvalue3(int Value3) { value3 = Value3; }

public int getValue() { return value; }

public int getValue2() { return value2; }

public int getValue3() { return value3; }

}//End of class

public class DoubleScore extends Slot { private int sides =3; private double num; private double value; private double value2; private double value3;

public DoubleScore() {

}

public double setNum(double total) {

if (value == 1 && value2 ==1 && value3==1) { num = Math.pow(total, 3); }

else if(value == 2 && value2 ==2 && value3 == 2) { num = Math.pow(total, 3); }

else if(value ==3 && value2 ==3 && value3 ==3) { num = Math.pow(total, 3); }

return num;

}

}

import javax.swing.*; // Needed for Swing classes import java.awt.event.*; // Needed for ActionListener Interface import javax.swing.event.*; import java.util.Random; import java.awt.*; import javax.swing.JOptionPane;

public class Final extends JFrame { private double total; private double total2; private double total3;

private final int sides = 3; private int value; private int value2; private int value3; private JPanel panel; private JLabel endLabel; private JLabel AmountLabel; private JLabel totalAmount; private JLabel imageLabel1; private JLabel imageLabel2; private JLabel imageLabel3; private JTextField EnteredMoney; private JTextField endMoney; private JTextField totalMoney; private JButton Amount; private final int WINDOW_WIDTH = 5000; private final int WINDOW_HEIGHT = 300;

public NatoliFinal() { setTitle("Dice Simulator");

setSize(WINDOW_WIDTH, WINDOW_HEIGHT);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

buildPanel();

setVisible(true); }

public void buildPanel() { AmountLabel = new JLabel("Amount Inserted: $");

EnteredMoney = new JTextField(10);

endLabel = new JLabel("You have won: $");

endMoney = new JTextField(10);

endMoney.setEditable(false);

totalAmount = new JLabel("Total amount won is");

totalMoney = new JTextField(10);

totalMoney.setEditable(false);

imageLabel1 = new JLabel();

imageLabel2 = new JLabel();

imageLabel3 = new JLabel();

Amount = new JButton("Spin");

Amount.addActionListener(new AmountListener());

JPanel panel = new JPanel(); JPanel panel2 = new JPanel(); JPanel panel3 = new JPanel(); JPanel panel4 = new JPanel();

panel = new JPanel(); panel2 = new JPanel(); panel3 = new JPanel(); panel4 = new JPanel();

panel.add(AmountLabel); panel.add(EnteredMoney); panel.add(endLabel); panel.add(endMoney); panel.add(totalAmount); panel.add(totalMoney); panel2.add(imageLabel1); panel2.add(imageLabel2); panel4.add(imageLabel3); panel3.add(Amount);

add(panel,BorderLayout.WEST); add(panel2,BorderLayout.NORTH); add(panel3,BorderLayout.SOUTH); add(panel4,BorderLayout.EAST);

}

private class AmountListener implements ActionListener { public void actionPerformed(ActionEvent e) {

Slot Roll = new Slot();

value = Roll.getValue(); value2 = Roll.getValue2(); value3 = Roll.getValue3();

String Emoney =""; double eMoney = 0.0;

double Doubel =0.0;

Emoney = EnteredMoney.getText();

eMoney = Double.parseDouble(Emoney);

switch(value) { case 1 : ImageIcon set = new ImageIcon("cherry.jpg"); imageLabel1.setIcon(set); break;

case 2: ImageIcon set2 = new ImageIcon("lemon.png"); imageLabel1.setIcon(set2); break;

case 3: ImageIcon set3 = new ImageIcon("watermelon.jpg"); imageLabel1.setIcon(set3); break;

}//end of vlaue switch

switch(value2) { case 1 : ImageIcon set = new ImageIcon("cherry.jpg"); imageLabel2.setIcon(set); break;

case 2: ImageIcon set2 = new ImageIcon("lemon.png"); imageLabel2.setIcon(set2); break;

case 3: ImageIcon set3 = new ImageIcon("watermelon.jpg"); imageLabel2.setIcon(set3); break;

}// end of value2 switch

switch(value3) { case 1 : ImageIcon set = new ImageIcon("cherry.jpg"); imageLabel3.setIcon(set); break;

case 2: ImageIcon set2 = new ImageIcon("lemon.png"); imageLabel3.setIcon(set2); break;

case 3: ImageIcon set3 = new ImageIcon("watermelon.jpg"); imageLabel3.setIcon(set3); break; }// end of value3 switch

DoubleScore D = new DoubleScore(); total3 = D.setNum(eMoney); endMoney.setText(String.format("%f",(total3)));

totalMoney.setText(String.format("%f",(total3)));

}

}

public static void main(String [] args) { new Final(); }

}

I am trying to corilate my slot class with my doubleslot class and my demo program so that when all three pictures are displayed on the screen the value entered is cubed. The classes that I have done so far are working, but I am getting a different set of random numbersfrom the slot class to my doubelslot class than I am from my slot class to my demo program?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

Students also viewed these Databases questions

Question

Draft a business plan.

Answered: 1 week ago

Question

Understand the roles of signs, symbols, and artifacts.

Answered: 1 week ago

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago