# 软件工程个人作业01

1.设计思想：了解题目要求，进行相关的定义与程序编写，再进行验证。

2.源代码：

//韩迪的出题算法
//2017/3/6

package dijia;
import java.util.Random;
import java.util.Scanner;

public class test1 {

public static void main(String[] args) {

System.out.println("整数运算请输入1；分数预算请输入2");

Random random = new Random();
Scanner scanner = new Scanner(System.in);
int bb = scanner.nextInt();

if(bb == 1)
{

System.out.println("请输入题目的个数：");
int M = scanner.nextInt();

//定义变量
int m=0;

//创建M个数组储存M道题
int [][] a = new int[M][4];

//产生30道题目
for(int i = 0;i < M;i++)
{
a[i][0] = random.nextInt(100);
a[i][2] = random.nextInt(100);
a[i][1] = random.nextInt(4);
}

//排除重复的题目
while(m <= (M - 1)*M/2)
{
for(int j = 0;j < M;j++)
{
for(int k = j+1;k < M;k++)
{
m++;
if((a[j][0] == a[k][0] && a[j][1] == a[k][1] && a[j][2] == a[k][2]) || (a[j][1] == 3 && a[j][2] == 0))
{

int b = (int)Math.random()*100;
int c = (int)Math.random()*100;
int d = (int)Math.random()*4;

a[k][0] = b;
a[k][1] = d;
a[k][2] = c;
}
}
}
}

//输出题目
for(int i = 0;i < M;i++)
{
if(a[i][1] == 0)
{
System.out.println(a[i][0]+"+"+a[i][2]+"=");
}
if(a[i][1] == 1)
{
System.out.println(a[i][0]+"-"+a[i][2]+"=");
}
if(a[i][1] == 2)
{
System.out.println(a[i][0]+"*"+a[i][2]+"=");
}
if(a[i][1] == 3)
{
System.out.println(a[i][0]+"/"+a[i][2]+"=");
}
}
}

//分数运算
if(bb == 2)
{
System.out.println("请输入题目的个数：");
int MM = scanner.nextInt();
int nn = 0;

//定义相关数组
int a1[] = new int [MM];//储存第一个分数的分子
int b1[] = new int [MM];//储存第二个分数的分子
int a2[] = new int [MM];//储存第一个分数的分母
int b2[] = new int [MM];//储存第二个分数的分母
int cc[] = new int [MM];//储存四则运算符号
char dd[] ={‘+‘,‘-‘,‘*‘,‘/‘};

for(int i = 0;i < MM;i++)
{
a1[i] = random.nextInt(100);
a2[i] = random.nextInt(100);
b1[i] = random.nextInt(100);
b2[i] = random.nextInt(100);
cc[i] = random.nextInt(4);

}
//排除的分数题目
while(nn <= MM*(MM-1)/2)
{
for(int iii = 0;iii < MM;iii++)
{
nn++;

for(int ii = iii+1;ii < MM;ii++)
{
nn++;

if( (cc[ii] == 3 && b1[ii] == 0) || b2[ii] == 0 || a2[ii] == 0 || (a1[ii] >= a2[ii]) || (b1[ii] >= b2[ii]) || (a1[ii] == a1[iii] && b1[ii] == b1[iii] && a2[ii] == a2[iii] && b2[ii] == b2[iii] && cc[ii] == cc[iii]))
{
a1[ii] = random.nextInt(100);
a2[ii] = random.nextInt(100);
b1[ii] = random.nextInt(100);
b2[ii] = random.nextInt(100);
cc[ii] = random.nextInt(4);
}
}
}
}

//输出题目
for(int jj = 0;jj < MM;jj++)
{
System.out.println("("+a1[jj]+"/"+a2[jj]+")"+dd[cc[jj]]+"("+b1[jj]+"/"+b2[jj]+")"+"=");
}

}
}
}

3.截图：

<1>

<2>

## 课程作业01：模仿JavaAppArguments.java示例，编写一个程序，此程序从命令行接收多个数字，求和之后输出结果。

1.设计思想: 首先是从JavaAppArguments.java示例开始,此示例已打印参数,定义数字 之和和作为存储单位的整型,然后将输入参数的字符串转化为整型,之后求和即可. 2.程序源码: //课程作业01 //李慧,2016.9.20 package demo; public class CommandParameterSum { public static void main(String[] args) { // TODO Auto-generated method stub Sys