Java实现四则运算 (3)

System.out.println("已成功将算式保存到"+fileName+",答案保存到"+answerName+",欢迎您的下次使用!");

}

}

6FormulaCustomTest

package cn.zhl.software;

import cn.zhl.fileCreate.FileRealization;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Map;

import java.util.Scanner;

public class FormulaCustomTest {

public static void main(String[] args) {

int formulaNum;

boolean if_MulDiv;int range;

boolean ifNeg_AddSub;boolean ifRem_Div;

boolean ifRed_Div;int lineNum;

Scanner scanner = new Scanner(System.in);

System.out.println("请输入需要算式个数:");

formulaNum=scanner.nextInt();

System.out.println("请输入需要乘除法(Y/N):");

if(scanner.next().equals("y")||scanner.next().equals("Y")){

if_MulDiv=true;

}else {

if_MulDiv=false;

}

System.out.println("请输入需要结果集范围(默认-n~n):");

range=scanner.nextInt();

System.out.println("请输入允许加减法出现负数(Y/N):");

if(scanner.next().equals("y")||scanner.next().equals("Y")){

ifNeg_AddSub=true;

}else {

ifNeg_AddSub=false;

}

System.out.println("请输入允许除法出现小数(Y/N):");

if(scanner.next().equals("y")||scanner.next().equals("Y")){

ifRem_Div=true;

}else {

ifRem_Div=false;

}

System.out.println("请输入允许除法结果换算成分数(Y/N):");

if(scanner.next().equals("y")||scanner.next().equals("Y")){

ifRed_Div=true;

}else {

ifRed_Div=false;

}

System.out.println("请输入算式每行个数:");

lineNum=scanner.nextInt();

//文件名

String fileName="";

System.out.println("请输入算式需要导入的文件名:");

fileName=scanner.next();

System.out.println("定制完成,正在随机生成算式。。。。");

long l = System.currentTimeMillis();

//算法生成器:算式个数,是否有乘除法,数值范围,加减法有无负数,除法又无余数,是否支持分数,打印每行个数

FormulaRealization formulaRealization = new FormulaRealization();

Map<String, ?> stringMap = formulaRealization.FormulaCustom(formulaNum,if_MulDiv,range,

ifNeg_AddSub,ifRem_Div,

ifRed_Div,lineNum);

long l2 = System.currentTimeMillis();

System.out.println("算式生成成功,耗时"+(l2-l)+"毫秒!");

FileRealization fileRealization = new FileRealization();

fileRealization.fileShow(stringMap,lineNum,fileName);

}

}

三、运行结果:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzxsjw.html