软件工程个人作业02

Posted 动漫人生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件工程个人作业02相关的知识,希望对你有一定的参考价值。

1.设计思想:分模块实现不同功能;正数,负数,运算符号,分数的数据结构定义分别定义;最简真分数的判断和菜单栏也独自分开;

求余,负数,规定取值范围等在主函数中放入主函数中,再用if语句对不同的功能进行进一步的规定,输出结果。

2.源代码:

    

package 四则运算2;
import java.util.*;
//正数的随机取值
class number1{
private int i;
private int j;
public void seti()
{
i = 1 + (int)(Math.random() * 100);
}
public int geti()
{
return i;
}
public void setj()
{
j = 1 + (int)(Math.random() * 99);
}
public int getj()
{
return j;
}

}
//负数的随机取值
class Number{
private int i;
private int j;
public void seti()
{
i = (-1) + (int)(Math.random() * (-100));
}
public int geti()
{
return i;
}
public void setj()
{
j = (-1) + (int)(Math.random() * (-99));
}
public int getj()
{
return j;
}

}
//运算符号的随机取值
class symbol{
private int a;
public void seta()
{
a = 1 + (int)(Math.random() * 4);
}
public int geta()
{
return a;
}
}
//分数的随机取值
class number2{
private int i;
private int j;
private int x;
private int y;
public void setnumber()
{
i = 1 + (int)(Math.random() * 100);
j = 1 + (int)(Math.random() * 99);
x = 1 + (int)(Math.random() * 100);
y = 1 + (int)(Math.random() * 99);
}
public int getnumberi()
{
return i;
}
public int getnumberj()
{
return j;
}
public int getnumberx()
{
return x;
}
public int getnumbery()
{
return y;
}


}
public class calculate {
public static void main(String args[])
{
menu();
System.out.println("请输入想要运行的计算");
Scanner scan = new Scanner(System.in);
int p;
p = scan.nextInt();
if(p == 1)
{
for(int i = 0 ; i <= 29 ; i ++){
number1 n1 = new number1();
int a1 , a2;
n1.seti();
a1 = n1.geti();
n1.setj();
a2 = n1.getj();
symbol s = new symbol();
int b;
s.seta();
b = s.geta();
if(b == 1)
System.out.println(a1 + "+" + a2 + "=" + ( a1 + a2 ) );
if(b == 2)
System.out.println(a1 + "-" + a2 + "=" + (a1 - a2));
if(b == 3)
System.out.println(a1 + "*" + a2 + "=" + (a1 * a2));
if(b == 4){
int c = a1 % a2;
int c1 = (a1 - c) / a2;
System.out.println(a1 + "/" + a2 + "=" + c1 + "余" + c);
}

}
}
if(p == 2){
for(int i = 0 ; i <= 29 ; i ++){
Number n1 = new Number();
int a1 , a2;
n1.seti();
a1 = n1.geti();
n1.setj();
a2 = n1.getj();
symbol s = new symbol();
int b;
s.seta();
b = s.geta();
if(b == 1)
System.out.println(a1 + "+" + "(" +a2 + ")" + "=" + ( a1 + a2 ) );
if(b == 2)
System.out.println(a1 + "-" + "(" +a2 + ")" + "=" + (a1 - a2));
if(b == 3)
System.out.println(a1 + "*" + "(" +a2 + ")" + "=" + (a1 * a2));
if(b == 4){
int c = ((-1) * a1) % ((-1) * a2);
int c1 = ((-1) * a1 - c) / ((-1) * a2);
System.out.println(a1 + "/" + "(" +a2 + ")" + "=" + c1 + "余" + c);
}


}
}
if(p == 3)
{
for(int i = 0 ; i <= 29 ; i++)
{
number2 n2 = new number2();
int b1 , b2 , b3 , b4;
n2.setnumber();
b1 = n2.getnumberi();
b2 = n2.getnumberj();
b3 = n2.getnumberx();
b4 = n2.getnumbery();
symbol s1 = new symbol();
int c;
s1.seta();
c = s1.geta();
if(c == 1)
System.out.println(simplify(b2 , b1) + "+" + simplify(b4 , b3) + "=" + simplify(b2 * b3 + b4 * b1 , b1 * b3));
if(c == 2)
System.out.println(simplify(b2 , b1) + "-" + simplify(b4 , b3) + "=" + simplify(b2 * b3 - b4 * b1 , b1 * b3));
if(c == 3)
System.out.println(simplify(b2 , b1) + "*" + simplify(b4 , b3) + "=" + simplify(b2 * b4 , b1 * b3));
if(c == 4)
System.out.println(simplify(b2 , b1) + "/" + simplify(b4 , b3) + "=" + simplify(b2 * b3 , b1 * b4));
}
}
if(p == 4)
{
int i = 0;
while(i < 30){
number1 n = new number1();
int a1 , a2;
n.seti();
a1 = n.geti();
n.setj();
a2 = n.getj();
if(a1 % a2 == 0)
{
i++;
System.out.println(a1 + "/" + a2 + "=" + (a1 / a2));
}
}
}
if(p == 5)
{
int i = 0;
while(i < 30){
number1 n = new number1();
int a1 , a2;
n.seti();
a1 = n.geti();
n.setj();
a2 = n.getj();
if(a1 % a2 != 0)
{
i++;
int c = a1 % a2;
int c1 = (a1 - c) / a2;
System.out.println(a1 + "/" + a2 + "=" + c1 + "余" + c);
}
}
}
if(p == 6)
{
System.out.println("请输入范围的左边界:");
Scanner scan1 = new Scanner(System.in);
int a3;
a3 = scan1.nextInt();
System.out.println("请输入范围的右边界:");
Scanner scan2 = new Scanner(System.in);
int a4;
a4 = scan1.nextInt();
int i = 0;
while(i < 30){
number1 n1 = new number1();
int a1 , a2;
n1.seti();
a1 = n1.geti();
n1.setj();
a2 = n1.getj();
symbol s = new symbol();
int b;
s.seta();
b = s.geta();
if(a1 >= a3 && a1 <= a4 && a2 >= a3 && a2 <= a4)
{
i++;
if(b == 1)
System.out.println(a1 + "+" + a2 + "=" + ( a1 + a2 ) );
if(b == 2)
System.out.println(a1 + "-" + a2 + "=" + (a1 - a2));
if(b == 3)
System.out.println(a1 + "*" + a2 + "=" + (a1 * a2));
if(b == 4){
int c = a1 % a2;
int c1 = (a1 - c) / a2;
System.out.println(a1 + "/" + a2 + "=" + c1 + "余" + c);
}
}
}
}
if(p == 7)
{

}


}
public static String simplify(int a,int b) //获得最简分数
{
int max = 0;
for(int i = 0 ;i < 100 ;i ++)
{
int n = i + 1 ;
if(a % n == 0 && b % n == 0)
max = n;

}
return (String)( a / max + "/" + b / max);
}
public static void menu()
{
System.out.println("1. 正数的四则运算");
System.out.println("2. 负数的四则运算");
System.out.println("3. 分数的四则运算");
System.out.println("4. 整除运算");
System.out.println("5. 非整除运算");
System.out.println("6. 规定数值范围的运算");
System.out.println("7. 带括号的四则运算");
}

}

                    

    

 

 项目计划日志:

日期/任务

听课

阅读课本

课下学习

 

日总计

周一

 0

 0

 0

 

 0

周二

0

0

0

 

0

周三

 0

 20min

40min

 

60min

周四

 0

 0

0

 

0

周五

100min

10min

50min

 

160min

周六

 0

 15min

60min

 

75min

周日

 0

 0

50min

 

50min

每周总结

 

100min 45min 200min  

345min

时间记录日志:

日期

开始时间

结束时间

中断时间

净时间

活动

备注

C

U

3.10

 

 

0

0

上课

 

 

 

3.11

20:00

21:00

10min

50min

看书,编程

写软件工程作业

 

 

3.12

19:00

21:00

15m

105min

看书,编程

学javaweb

 

 

3.13

19:00

20:00

10m

50min

编程

软件工程作业

 

 

 

 

 

 

 

 

 

 

 

缺陷记录日志:

3/12:除数中含有0报错;

         漏掉分号;

 

以上是关于软件工程个人作业02的主要内容,如果未能解决你的问题,请参考以下文章

软件工程个人作业02

软件工程个人作业02

软件工程个人作业02

软件工程个人作业02

软件工程个人作业02

软件工程个人作业02