Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int rando(int i) {
- Random randomGenerator = new Random();
- int randomInt = randomGenerator.nextInt();
- i = randomInt;
- return rando();
- }
- public static int add(int i, int i)
- {
- int a = i+i;
- return a;
- }
- b1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e){
- String b = "Click For Answer";
- b1.setText(b.toString());
- jl.setText(prob.toString());
- }
- });
- public class MathProblems {
- private static final int MAX_NUMBER = 10;
- private static final Scanner in = new Scanner(System.in);
- private static final Random random = new Random();
- public static void main (String... args) {
- new MathProblems().run();
- }
- public void run() {
- while(true) {
- final int a = random.nextInt(MAX_NUMBER);
- final int b = random.nextInt(MAX_NUMBER);
- final int type = random.nextInt(4);
- switch (type) {
- case 0:
- add(a, b);
- break;
- case 1:
- subtract(a, b);
- break;
- case 2:
- multiply(a, b);
- break;
- }
- }
- }
- private void add(final int a, final int b) {
- final int expected = a + b;
- final int answer = askQuestion(a + " + " + b + "=");
- checkResult(expected, answer);
- }
- private void subtract(final int a, final int b) {
- final int expected = a - b;
- final int answer = askQuestion(a + " - " + b + "=");
- checkResult(expected, answer);
- }
- private void multiply(final int a, final int b) {
- //leaving this for you..
- }
- private int askQuestion(final String question) {
- System.out.print(question);
- return in.nextInt();
- }
- private void checkResult(final int expected, final int answer) {
- if (expected == answer) {
- System.out.println("Correct answer! You rock!");
- } else {
- System.out.println("WROOONG! You suck!");
- }
- }
- }
- //or whatever numbers you want here
- int myLow = -10;
- int myHigh = 10;
- public int randBetween(int low, int high){
- return (int) Math.round(Math.random() * (high - low)) + low;
- }
- public String makeProblem(AtomicLong answer){
- int a = randBetween(myLow, myHigh);
- int b = randBetween(myLow, myHigh);
- double result;
- char operator;
- switch(randBetween(1,4)){
- case 1:
- operator = '+';
- result = a + b;
- break;
- case 2:
- operator = '-';
- result = a - b;
- break;
- case 3:
- operator = '*';
- result = a * b;
- break;
- case 4:
- operator = '/';
- result = (double) a / b;
- break;
- default:
- operator = '