301
社区成员
发帖
与我相关
我的任务
分享| 类 | 总行数 | 源代码行数 | 属性个数 | 方法个数 |
|---|---|---|---|---|
| Definer.java | 87 | 62 | 2 | 4 |
| DeriveFactor.java | 24 | 16 | 0 | 3 |
| Exp.java | 19 | 14 | 1 | 3 |
| ExpFactor.java | 62 | 52 | 2 | 4 |
| Expr.java | 51 | 42 | 1 | 6 |
| ExprFactor.java | 53 | 41 | 1 | 4 |
| Factor.java | 13 | 8 | 0 | 3 |
| FunFactor.java | 45 | 29 | 2 | 4 |
| Lexer.java | 93 | 82 | 2 | 6 |
| Main.java | 51 | 25 | 0 | 1 |
| Mono.java | 21 | 15 | 1 | 3 |
| MyOutputer.java | 58 | 50 | 0 | 2 |
| NumFactor.java | 34 | 27 | 1 | 4 |
| Parse.java | 266 | 220 | 1 | 11 |
| Poly.java | 304 | 250 | 1 | 11 |
| PowerFactor.java | 45 | 36 | 2 | 4 |
| PreProcesser.java | 61 | 53 | 0 | 1 |
| Simplify.java | 30 | 27 | 0 | 1 |
| Term.java | 74 | 61 | 2 | 6 |
| Token.java | 26 | 21 | 3 | 3 |
| Unit.java | 42 | 30 | 3 | 6 |
| 总计 | 1459 | 1161 | 25 | 90 |
| Method | CogC | ev(G) | iv(G) | v(G) |
|---|---|---|---|---|
| Main.main(String[]) | 1 | 1 | 2 | 2 |
| baseclass.Exp.Exp(Poly) | 0 | 1 | 1 | 1 |
| baseclass.Exp.getPoly() | 0 | 1 | 1 | 1 |
| baseclass.Exp.toString() | 0 | 1 | 1 | 1 |
| baseclass.Mono.Mono(BigInteger) | 0 | 1 | 1 | 1 |
| baseclass.Mono.getExp() | 0 | 1 | 1 | 1 |
| baseclass.Mono.toString() | 0 | 1 | 1 | 1 |
| baseclass.Poly.addPoly(Poly) | 15 | 1 | 7 | 7 |
| baseclass.Poly.addUnit(Unit) | 58 | 13 | 15 | 16 |
| baseclass.Poly.getPolys() | 0 | 1 | 1 | 1 |
| baseclass.Poly.getPolysScale() | 3 | 1 | 2 | 3 |
| baseclass.Poly.isEqual(Poly) | 44 | 8 | 18 | 19 |
| baseclass.Poly.isZero() | 0 | 1 | 1 | 1 |
| baseclass.Poly.miss(Unit) | 1 | 1 | 2 | 2 |
| baseclass.Poly.mulPoly(Poly) | 13 | 1 | 7 | 7 |
| baseclass.Poly.powPoly(BigInteger) | 7 | 1 | 6 | 6 |
| baseclass.Poly.toString() | 4 | 2 | 3 | 4 |
| baseclass.Poly.vers() | 3 | 1 | 3 | 3 |
| baseclass.Token.Token(Type, String) | 0 | 1 | 1 | 1 |
| baseclass.Token.getStr() | 0 | 1 | 1 | 1 |
| baseclass.Token.getType() | 0 | 1 | 1 | 1 |
| baseclass.Unit.Unit(BigInteger, Mono, Exp) | 0 | 1 | 1 | 1 |
| baseclass.Unit.getExp() | 0 | 1 | 1 | 1 |
| baseclass.Unit.getPoly() | 0 | 1 | 1 | 1 |
| baseclass.Unit.getXi() | 0 | 1 | 1 | 1 |
| baseclass.Unit.setXi(BigInteger) | 0 | 1 | 1 | 1 |
| baseclass.Unit.toString() | 0 | 1 | 1 | 1 |
| entity.DeriveFactor.DeriveFactor(ArrayList) | 0 | 1 | 1 | 1 |
| entity.DeriveFactor.toPoly() | 0 | 1 | 1 | 1 |
| entity.DeriveFactor.toString() | 0 | 1 | 1 | 1 |
| entity.ExpFactor.ExpFactor(Factor, BigInteger) | 0 | 1 | 1 | 1 |
| entity.ExpFactor.derive() | 3 | 3 | 3 | 3 |
| entity.ExpFactor.toPoly() | 2 | 2 | 2 | 2 |
| entity.ExpFactor.toString() | 0 | 1 | 1 | 1 |
| entity.Expr.Expr(ArrayList) | 0 | 1 | 1 | 1 |
| entity.Expr.derive() | 1 | 1 | 2 | 2 |
| entity.Expr.getTerms() | 0 | 1 | 1 | 1 |
| entity.Expr.setTerms(ArrayList) | 0 | 1 | 1 | 1 |
| entity.Expr.toPoly() | 1 | 1 | 2 | 2 |
| entity.Expr.toString() | 1 | 1 | 2 | 2 |
| entity.ExprFactor.ExprFactor(ArrayList, String) | 0 | 1 | 1 | 1 |
| entity.ExprFactor.derive() | 1 | 1 | 2 | 2 |
| entity.ExprFactor.toPoly() | 2 | 2 | 2 | 2 |
| entity.ExprFactor.toString() | 0 | 1 | 1 | 1 |
| entity.FunFactor.FunFactor(String) | 0 | 1 | 1 | 1 |
| entity.FunFactor.derive() | 0 | 1 | 1 | 1 |
| entity.FunFactor.toPoly() | 0 | 1 | 1 | 1 |
| entity.FunFactor.toString() | 0 | 1 | 1 | 1 |
| entity.NumFactor.NumFactor(String) | 0 | 1 | 1 | 1 |
| entity.NumFactor.derive() | 0 | 1 | 1 | 1 |
| entity.NumFactor.toPoly() | 0 | 1 | 1 | 1 |
| entity.NumFactor.toString() | 0 | 1 | 1 | 1 |
| entity.PowerFactor.PowerFactor(String, String) | 0 | 1 | 1 | 1 |
| entity.PowerFactor.derive() | 1 | 1 | 2 | 2 |
| entity.PowerFactor.toPoly() | 0 | 1 | 1 | 1 |
| entity.PowerFactor.toString() | 0 | 1 | 1 | 1 |
| entity.Term.Term(ArrayList, int) | 0 | 1 | 1 | 1 |
| entity.Term.derive() | 6 | 1 | 4 | 4 |
| entity.Term.getFactors() | 0 | 1 | 1 | 1 |
| entity.Term.getMark() | 0 | 1 | 1 | 1 |
| entity.Term.toPoly() | 3 | 2 | 3 | 3 |
| entity.Term.toString() | 3 | 1 | 3 | 3 |
| utils.Definer.addFunc(String) | 4 | 1 | 2 | 5 |
| utils.Definer.callFunc(String, ArrayList) | 1 | 1 | 2 | 2 |
| utils.Definer.getTrans(String, Integer) | 0 | 1 | 1 | 1 |
| utils.Definer.printMap() | 3 | 1 | 3 | 3 |
| utils.Lexer.getTokens() | 0 | 1 | 1 | 1 |
| utils.Lexer.inputToTokens(String) | 7 | 1 | 19 | 19 |
| utils.Lexer.isNotFinished() | 0 | 1 | 1 | 1 |
| utils.Lexer.move() | 0 | 1 | 1 | 1 |
| utils.Lexer.now() | 0 | 1 | 1 | 1 |
| utils.Lexer.nowOffset(int) | 0 | 1 | 1 | 1 |
| utils.MyOutputer.getSs(Expr) | 5 | 2 | 4 | 4 |
| utils.MyOutputer.shared(Expr) | 5 | 1 | 4 | 4 |
| utils.Parse.Parse(Lexer) | 0 | 1 | 1 | 1 |
| utils.Parse.parseDerive_06() | 0 | 1 | 1 | 1 |
| utils.Parse.parseExpr() | 7 | 1 | 5 | 7 |
| utils.Parse.parseFactor() | 1 | 7 | 7 | 7 |
| utils.Parse.parseFactorExp_04() | 20 | 4 | 7 | 7 |
| utils.Parse.parseFactorExpr_07() | 14 | 3 | 6 | 7 |
| utils.Parse.parseFactorFun_05() | 2 | 1 | 3 | 3 |
| utils.Parse.parseFactorNum_01() | 1 | 1 | 2 | 2 |
| utils.Parse.parseFactorPower_03() | 20 | 4 | 7 | 7 |
| utils.Parse.parseFactorSignedNum_02() | 6 | 2 | 4 | 4 |
| utils.Parse.parseTerm(int) | 2 | 1 | 3 | 3 |
| utils.PreProcesser.inputToStd(String) | 33 | 1 | 8 | 12 |
| utils.Simplify.simplify(String) | 2 | 2 | 1 | 2 |
| Total | 306 | 129 | 288 | 243 |
| Average | 3.52 | 1.48 | 2.62 | 2.79 |
| Class | 循环依赖 | 该类直接依赖 | Dcy* | 直接依赖该类 | Dpt* | PDcy | PDpt |
|---|---|---|---|---|---|---|---|
| Main | 0 | 6 | 20 | 0 | 0 | 2 | 0 |
| baseclass.Exp | 2 | 1 | 3 | 6 | 15 | 1 | 3 |
| baseclass.Mono | 0 | 0 | 0 | 6 | 16 | 0 | 3 |
| baseclass.Poly | 2 | 3 | 3 | 11 | 15 | 1 | 3 |
| baseclass.Token | 0 | 1 | 1 | 2 | 4 | 1 | 1 |
| baseclass.Token.Type | 0 | 0 | 0 | 3 | 5 | 0 | 2 |
| baseclass.Unit | 2 | 2 | 3 | 5 | 15 | 1 | 3 |
| entity.DeriveFactor | 0 | 3 | 9 | 0 | 0 | 2 | 0 |
| entity.ExpFactor | 0 | 7 | 9 | 1 | 3 | 2 | 1 |
| entity.Expr | 2 | 3 | 8 | 5 | 10 | 2 | 3 |
| entity.ExprFactor | 2 | 5 | 8 | 4 | 10 | 2 | 2 |
| entity.FunFactor | 1 | 6 | 19 | 1 | 2 | 3 | 1 |
| entity.NumFactor | 0 | 5 | 5 | 4 | 11 | 2 | 2 |
| entity.PowerFactor | 0 | 7 | 9 | 1 | 3 | 2 | 1 |
| entity.Term | 2 | 3 | 8 | 7 | 10 | 2 | 2 |
| utils.Definer | 0 | 4 | 12 | 2 | 3 | 2 | 2 |
| utils.Lexer | 0 | 2 | 2 | 3 | 3 | 1 | 3 |
| utils.MyOutputer | 0 | 6 | 11 | 2 | 4 | 3 | 2 |
| utils.Parse | 1 | 12 | 19 | 2 | 2 | 3 | 2 |
| utils.PreProcesser | 0 | 0 | 0 | 3 | 6 | 0 | 3 |
| utils.Simplify | 0 | 1 | 1 | 1 | 5 | 1 | 1 |

第一个Pakage,entity内都是有关表达式、项、因子的类。

第二个Pakage,baseclass内都是有关合并同类项的类,用于对各类项都实现统一的定义( Unit = ax^nexp(\sum Unit) ),因此设计Unit类时有xi,exp,poly三个属性分别代表a,n和exp的指数。各个类具体设计考虑如下:

第三个Pakage,utils是一些工具类,他们的用途如下:
优点:
缺点:

第二次作业
第二次作业难度依旧很大。我的思考过程如下。
首先是如何合并同类项。在第二次作业的形式化表达( Unit = ax^nexp( \sum Unit ) )下,判断两个单项式相等不仅要判断a和n,还要判断exp中的(\sum Unit)是否相等,而每个(Unit)中仍有可能继续嵌套(\sum Unit)。参考学长的做法,以及和同学们思考讨论之后,得出了递归判等的方法。伪代码如下:
在完成了( Unit = ax^nexp( \sum Unit ) )的同类项判断之后,在第一次作业的基础上修改用于合并同类项的方法addPoly(),powPoly(),addUnit()即可
类图如下:


新的迭代情景:
对表达式进行定积分( \int_{0}^{x} )
可扩展性:
和求导的设计思路类似,对每个继承了Factor接口的类实现一个integral()方法,按照定积分的积分法则对每种情况进行积分即可,比如:
第一次作业bug:
第二次作业bug:
添加括号
这是因为没有考虑到返回的多项式/自定义函数代入后的表达式是可能会作为 "因子" 的,比如作为FactorExp的因子,这时根据括号必要性的要求,必须在外面加上一层括号,否则会导致FactorExp不能正确的解析。
原因: 对括号必要性的要求理解的不是非常彻底
poly的add的时候,如果unit.getXi()是0的话,就不要add进polys了,保持polys为空
这是为了维持判断poly判等的递归出口条件,当系数a=0的时候,要清空这个polys列表,才能成功达到递归出口,如果再以a=0的形式加入一个Unit斤polys列表,那么就会一直同类项判等就会递归下去
x的指数会超过Integer
这是没有注意到第二次作业没有对最终结果的指数加以限制,所以没有把系数的数据类型及时改成BigInteger
第三次作业bug:
总结:


public class Simplify {
public static String simplify(String str) {
// 再化简一下加减号,省略^1和去掉*x^0 1*
String suf1 = PreProcesser.inputToStd(str);
String suf22 = suf1.replace("*exp()", "");
String suf2 = suf22.replace("*exp(())", "");
String suf3 = suf2.replaceAll("\\^1$", "");
String suf4 = suf3.replaceAll("\\^1\\+","+");
String suf5 = suf4.replaceAll("\\^1-","-");
String suf66 = suf5.replaceAll("\\^1\\)",")");
String suf6 = suf66.replaceAll("\\^1\\*","*");
String suf7 = suf6.replace("*x^0", "");
String suf8 = suf7.replace("+1*", "+");
String suf9 = suf8.replace("-1*", "-");
String suf10 = suf9.replace("(1*", "(");
String suf11 = suf10.replaceFirst("^1\\*", "");
String suf12 = suf11.replaceFirst("^-1\\*", "-");
String suf13 = suf12.replaceAll("[+-]0\\*x\\^\\d+", "");
String suf14 = suf13.replaceAll("^0\\*x\\^\\d+", "");
String suf15 = suf14.replace("exp((x))", "exp(x)");
if (suf15.isEmpty()) {
return "0";
} else {
return suf15;
}
}
}