个人作业1——四则运算题目生成程序(基于java)
2024-10-19 02:29:26
项目代码:
https://git.coding.net/YJh_/11.git
题目要求:
除了整数以外,还要支持真分数的四则运算,真分数的运算,例如:/ + / = /
运算符为 +, −, ×, ÷
并且要求能处理用户的输入,并判断对错,打分统计正确率。
要求能处理用户输入的真分数, 如 /, / 等
使用 -n 参数控制生成题目的个数,例如执行下面命令将生成10个题目
Myapp.exe -n
程序设计:
主要功能:
- 真分数的四则运算
- 按照用户输入的题数出题
- 能得出用户的正确率
设计的主要函数以及属性:
主要算法代码:
public static int commonDivisor(int x, int y) // 计算2个数的最大公约数。按绝对值计算。
{
if (x == 0 || y == 0) {
return 1;
}
int x1;
int y1; x1 = (Math.abs(x) > Math.abs(y)) ? Math.abs(x) : Math.abs(y); // 使x1>y1.
y1 = (Math.abs(x) > Math.abs(y)) ? Math.abs(y) : Math.abs(x);
int z = 1;
while (z != 0) {
z = x1 % y1;
x1 = y1;
y1 = z;
}
return x1;
}
主要四则运算方法:
Calculator add(Calculator r) { // 加法运算
int a = r.getNumerator();
int b = r.getDenominator();
int newNumerator = numerator * b + denominator * a;
int newDenominator = denominator * b; int maxCommon = commonDivisor(newNumerator, newDenominator);
Calculator result = new Calculator(newNumerator/ maxCommon, newDenominator/ maxCommon);
return result;
} Calculator sub(Calculator r) { // 减法运算
int a = r.getNumerator();
int b = r.getDenominator();
int newNumerator = numerator * b - denominator * a;
int newDenominator = denominator * b; int maxCommon = commonDivisor(newNumerator, newDenominator);
Calculator result = new Calculator(newNumerator/ maxCommon, newDenominator/ maxCommon);
return result;
} Calculator muti(Calculator r) { // 乘法运算
int a = r.getNumerator();
int b = r.getDenominator();
int newNumerator = numerator * a;
int newDenominator = denominator * b; int maxCommon = commonDivisor(newNumerator, newDenominator);
Calculator result = new Calculator(newNumerator/ maxCommon, newDenominator/ maxCommon);
return result;
} Calculator div(Calculator r) { // 除法运算
int a = r.getNumerator();
int b = r.getDenominator();
int newNumerator = numerator * b;
int newDenominator = denominator * a; int maxCommon = commonDivisor(newNumerator, newDenominator);
Calculator result = new Calculator(newNumerator/ maxCommon, newDenominator/ maxCommon);
return result;
}
程序测试:
项目总结:
由于java学得并不好,重新回去看了java笔记学习,也上网查了一些资料,包括如何提交代码到码市,装egit的时候,因为下载的eclipse是中文版的,都不大懂,安装了一直出差错,所以前前后后花费了挺多的时间了,请教了班级里的一些比较厉害的同学,做出了这个程序。从中深刻了解到,平时要多多实践,熟能生巧。纸上得来终觉浅,绝知此事要躬行。
PSP表格
PSP2.1 | Personal Software Process Stages | Time (%) Senior Student | Time (%) |
Planning | 计划 | 8 | 15 |
· Estimate | 估计这个任务需要多少时间 | 8 | 15 |
Development | 开发 | 20 | 15 |
· Analysis | 需求分析 (包括学习新技术) | 1 | 1 |
· Design Spec | 生成设计文档 | 1 | 1 |
· Design Review | 设计复审 | 0 | 0 |
· Coding Standard | 代码规范 | 10 | 7 |
· Design | 具体设计 | 8 | 9 |
· Coding | 具体编码 | 6 | 6 |
· Code Review | 代码复审 | 1 | 1 |
· Test | 测试(自我测试,修改代码,提交修改) | 3 | 3 |
Reporting | 报告 | 10 | 10 |
·Test Report | 测试报告 | 8 | 7 |
· Size Measurement | 计算工作量 | 2 | 2 |
·Postmortem & Process Improvement Plan | 并提出过程改进计划 | 0 | 0 |
最新文章
- JavaScript和jQuery的类型判断
- Spring事务
- 使用ajaxfileupload插件进行Ajax Post 异步提交多个文件
- Redis的5种数据结构
- zend studio 9.0.4 破解、汉化和字体颜色及快捷键相关设置
- paip.基于urlrewrite的反向代理以及内容改写
- C#开发ActiveX插件-aspx中嵌入
- LeetCode----Word Ladder 2
- git的初步使用
- 场景类(CCSence)
- HDOJ 1326 Box of Bricks(简单题)
- 配置Tomcat中的Context元素中的中文问题
- 英特尔发布全新英特尔® INDE 2015工具套件
- 前端笔试题 JS部分
- 莫烦scikit-learn学习自修第六天【特征值矩阵标准化】
- Win10系列:C#应用控件基础3
- (10)The secret to great opportunities? The person you haven't met yet
- Axure 验证码、进度条、分页条(翻页)、搜索框、选项卡
- 【转载】C#调用C++ DLL
- Sql Server 创建表添加说明
热门文章
- [BZOJ 1054][HAOI 2008]移动玩具 状态压缩
- Symbolic link and hard link的区别(linux)
- Lua table.sort排序
- 第3天:CSS浮动、定位、表格、表单总结
- 关于web.xml中的<;welcome-file-list>;
- 利用pyinotify监控文件内容,像tailf命令但比它更强
- 分享:SringBuffer与String的区别
- 初入angular4——实际项目搭建总结
- Andrew Ng机器学习课程笔记--week5(上)
- LaTeX的表格插入与排版