I have to have a random number generator that gets a number from the user and then generates 10000 random numbers between 1 and the users number then figures min, max, and mean. Here is what I have so far. I am stuck on the actionPerformed method. I am a total noob so please try to explain your answers.
MY ISSUE
I have the JApplet coded just can’t figure out the action performed method. I have searched Google high and low for help and the chapter covered in the book this week in appendix c and they don’t explain how to do what we are asked to do. I have completed every other assignment in the class on my own but can’t seem to get this one and have spent 19 hours on it so far.
How to get all of the numbers added to the array list?
package randomNums;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import static java.lang.Math.*;
import javax.swing.*;
import java.applet.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
public class RandomNums extends Applet implements ActionListener {
/**
*
*/
// PAINT METHOD
public void paint(Graphics g)
{
Font font = new Font("Arial", Font.BOLD, 18);
g.setFont(font);
g.setColor(Color.WHITE);
g.drawString("Enter A Number", 70, 25);
resize(350, 350);
this.setBackground(Color.BLUE);
}
// CREATES OBJECTS
private static final long serialVersionUID = 1L;
TextField text1, text2, text3, text5;
Label label1, label2, label3, label4;
Button button;
Font font = new Font("Arial", Font.BOLD, 11);
private double all;
// INIT METHOD
public void init() {
setLayout(null);
repaint();
// YOUR NUMBER LABEL
label1 = new Label("Your Number ");
label1.setBounds(25, 35, 100, 20);
setFont(font);
add(label1);
// YOUR NUMBER ENTRY
text1 = new TextField(5);
text1.setBounds(150, 30, 100, 25);
add(text1);
// MAXIMUM
label2 = new Label("The Maximum Number Is: ");
label2.setBounds(25, 100, 150, 25);
setFont(font);
add(label2);
// MAXIMUM ANSWER
text2 = new TextField(5);
text2.setBounds(180, 100, 50, 25);
add(text2);
// MINIMUM
label3 = new Label("The Minimum Number Is: ");
label3.setBounds(25, 170, 150, 25);
setFont(font);
add(label3);
// MINIMUM ANSWER
text5 = new TextField(5);
text5.setBounds(180, 170, 50, 25);
add(text5);
// MEAN
label4 = new Label("The Mean is: ");
label4.setBounds(25, 135, 150, 25);
setFont(font);
add(label4);
// MEAN ANSWER
text3 = new TextField(5);
text3.setBounds(180, 135, 50, 25);
add(text3);
// BUTTON
button = new Button("Enter");
button.setBounds(90, 70, 100, 20);
add(button);
// ACTION LISTENER
button.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
Random ran = new Random(10000);
try {
//NOT SURE HOW TO GET ALL OF THE NUMBERS ADDED TO THE ARRAY LIST
double[] arrList = ran();
//THIS IS NOT WORKING RIGHT ONLY STORING ONE VALUE
all = ran.nextDouble();
for (int i = 0; i < arrList.length; i++) {
System.out.println(arrList[i] + " ");
//THIS IS IN THERE FOR MY TESTING PURPOSES NEED TO TAKE OUT BEFORE SUBMITTING
System.out.println(arrList);
final double TIMES = (double) 10000;
final String LIMIT = text1.getText();
Double.parseDouble(LIMIT);
//FOR LOOP
for (int x = 1; x < TIMES; ++x);
//SETS TEXT FOR MIN BOX (NOT SURE IF IT IS DOING THE CALCULATIONS RIGHT)
text5.setText(ran.nextDouble() + "");
//my comment: another variable after for loop to get mean , fix numbers being saved to an array so they can be added and divided to get mean,
}
}
catch (NumberFormatException m) {
if (getText(text1) == 0)
JOptionPane.showMessageDialog(this,
"Please enter a number between 1- 10,000");
}
}
private int getText(TextField text12) {
// TODO Auto-generated method stub
return 0;
}
}