package rjgz;
import java.util.Random;
public class BinaryOperation {
private int Upper = 100;
private int Lower = 0;
private int Right_operand = 0;
public int getUpper() {
return Upper;
}
public void setUpper(int upper) {
Upper = upper;
}
public int getLower() {
return Lower;
}
public void setLower(int lower) {
Lower = lower;
}
public int getRight_operand() {
return Right_operand;
}
public void setRight_operand(int right_operand) {
Right_operand = right_operand;
}
public int getLeft_operand() {
return Left_operand;
}
public void setLeft_operand(int left_operand) {
Left_operand = left_operand;
}
public int getThird_operand() {
return Third_operand;
}
public void setThird_operand(int third_operand) {
Third_operand = third_operand;
}
public int getValue() {
return Value;
}
public void setValue(int value) {
Value = value;
}
public char getOperator() {
return Operator;
}
public void setOperator(char operator) {
Operator = operator;
}
public char getOperator2() {
return Operator2;
}
public void setOperator2(char operator2) {
Operator2 = operator2;
}
private int Left_operand = 0;
private int Third_operand = 0;
private int Value = 100;
private char Operator = '+';
private char Operator2 = '+';
public int calculate(){
if(Operator=='+'&&Operator2=='+'){
Value=Right_operand+Left_operand+Third_operand;
}else if (Operator=='-'&&Operator2=='+'){
Value=Left_operand-Right_operand+Third_operand;
}else if(Operator=='+'&&Operator2=='-'){
Value=Left_operand+Right_operand-Third_operand;
}else if(Operator=='-'&&Operator2=='-'){
Value=Left_operand-Right_operand-Third_operand;
}
return Value;
}
BinaryOperation(int upper,int lower){
Random random = new Random();
this.Upper=upper;
this.Lower=lower;
Left_operand=random.nextInt(upper - lower + 1) + lower;
Right_operand=random.nextInt(upper - lower + 1) + lower;
Third_operand=random.nextInt(upper - lower + 1) + lower;
int h=random.nextInt(2);
int h2=random.nextInt(2);
if (h==1)Operator='+';
else Operator='-';
if (h2==1)Operator2='+';
else Operator2='-';
calculate();
}
@Override
public String toString() {
return "BinaryOperation{" +
"Right_operand=" + Right_operand +
", Left_operand=" + Left_operand +
", Value=" + Value +
", Operator=" + Operator +
", Operator2=" + Operator2 +
'}';
}
public Boolean equals2(BinaryOperation two){
return this.toString().equals(two.toString());
}
}
package rjgz;
import java.util.Scanner;
public class ShiYong {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.print("请选择参数范围-> ");
int fanWei=scanner.nextInt();
int fanWei2=scanner.nextInt();
Exercise exercise=new Exercise();
for (int i = 0; i < 50; i++) {
BinaryOperation b=new BinaryOperation(fanWei2,fanWei);
while (!exercise.Check(b)&&b.getValue()<0&&b.getValue()>100){
b=new BinaryOperation(fanWei2,fanWei);
}
exercise.list.add(b);
}
exercise.showList();
}
}
package rjgz;
import java.util.ArrayList;
import java.util.List;
public class Exercise {
public List<BinaryOperation> list=new ArrayList<>();
public void showList(){
int i=0;
for (BinaryOperation b :
list) {
System.out.print(b.getLeft_operand()+" "+b.getOperator()+" "+b.getRight_operand()+" "+b.getOperator2()+" "+b.getThird_operand()+" = ");
i++;
if (i%5==0){System.out.println();}
}
}
public Boolean Check(BinaryOperation b){
for (BinaryOperation bb :
list) {
if (bb.equals2(b)) {
return false;
}}
return true;
}
}