Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.mathapplication;
- import java.util.Random;
- public class Exercise {
- private static Random rnd = new Random();
- private int n1;
- private int n2;
- private String op;
- private double value;
- public Exercise() {
- n1 = Settings.min + rnd.nextInt(Settings.max - Settings.min + 1);
- n2 = Settings.min + rnd.nextInt(Settings.max - Settings.min + 1);
- int opIndex = rnd.nextInt(4);
- while (!isOpAllowd(opIndex)) {
- opIndex = rnd.nextInt(4);
- }
- switch (opIndex) {
- case 0:
- op = "+";
- value = n1 + n2;
- break;
- case 1:
- op = "-";
- value = n1 - n2;
- break;
- case 2:
- op = "*";
- value = n1 * n2;
- break;
- case 3:
- op = "/";
- value = n1 / n2;
- break;
- }
- }
- public int getN1() {
- return n1;
- }
- public int getN2() {
- return n2;
- }
- public String getOp() {
- return op;
- }
- public double getValue() {
- return value;
- }
- private boolean isOpAllowd(int op) {
- boolean allowed = false;
- switch (op) {
- case 0:
- allowed = Settings.add;
- break;
- case 1:
- allowed = Settings.sub;
- break;
- case 2:
- allowed = Settings.mul;
- break;
- case 3:
- allowed = Settings.div;
- break;
- }
- return allowed;
- }
- }
Add Comment
Please, Sign In to add comment