20165230 《Java程序设计》实验三 敏捷开发与XP实践 实验报告

一、实验报告封面

课程:Java程序设计 班级:1652班 姓名:田坤烨 学号:20165230 成绩

指导教师:娄嘉鹏 实验日期:2018年4月16日

实验时间:13:45 - 3:25

实验序号:实验三 实验名称:敏捷开发与XP实践

实验内容

  1. XP基础
  2. XP核心实践
  3. 相关工具

实验要求

  1. 没有Linux基础的同学建议先学习《Linux基础入门(新版)》《Vim编辑器》 课程;
  2. 完成实验、撰写实验报告,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用,程序的编辑,调试,运行等)、解决办法(空洞的方法如“查网络”、“问同学”、“看书”等一律得0分)以及分析(从中可以得到什么启示,有什么收获,教训等);
  3. 实验报告中统计自己的PSP(Personal Software Process)时间;
  4. 严禁抄袭。

二、实验内容及步骤

(一)编码标准

  • 编程标准使代码更容易阅读和理解,甚至可以保证其中的错误更少。编程标准包含:具有说明性的名字、清晰的表达式、直截了当的控制流、可读的代码和注释,以及在追求这些内容时一致地使用某些规则和惯用法的重要性。
  • 没有缩进的代码
public class CodeStandard {
public static void main(String [] args){
StringBuffer buffer = new StringBuffer();
buffer.append('S');
buffer.append("tringBuffer");
System.out.println(buffer.charAt(1));
System.out.println(buffer.capacity());
System.out.println(buffer.indexOf("tring"));
System.out.println("buffer = " + buffer.toString());
if(buffer.capacity()<20)
buffer.append("1234567");
for(int i=0; i<buffer.length();i++)
System.out.println(buffer.charAt(i));
}
}
  • 在IDEA中规范缩进

  • 规范后的代码

  • 研究code菜单

  1. Move Line/statement Down/Up:将某行、表达式向下、向上移动一行
  2. generate可以自动创建类里面任何字段的 getter 与 setter 方法
  3. Reformat Code:格式化代码
  4. suround with:代码块环绕
  5. comment with line/block comment:把选中它区域变成注释
  6. show reformat file dialog:按照格式自动对齐
  7. Optimize imports:去除不必要的imports
  8. Insert Live Template:插入一些记不起来的 Live Template 缩写
  • 个人觉得最好用的是generate功能,在编程时用到generate可以省去编写简单方法的功夫,提高效率。如getter and setter

(二)下载搭档实验二的Complex代码,加入不少于三个JUnit单元测试用例

  • 代码如下:
import junit.framework.TestCase;

public class ComplexTest extends TestCase {
Complex a=new Complex(1,2);
Complex b=new Complex(-2,-1);
Complex c=new Complex(4,-2);
public void testComplexAdd() throws Exception {
assertEquals(5,2+3);
assertEquals(new Complex(-1,1),a.ComplexAdd(b));
assertEquals(new Complex(5,0),a.ComplexAdd(c)); }
public void testComplexSub() throws Exception {
assertEquals(6,9 - 3);
assertEquals(new Complex(3,3),a.ComplexSub(b));
assertEquals(new Complex(-3,4),a.ComplexSub(c)); }
public void testComplexMulti() throws Exception {
assertEquals(6,2 * 3);
assertEquals(new Complex(0,-5),a.ComplexMulti(b));
assertEquals(new Complex(8,6),a.ComplexMulti(c)); }
public void testComplexDiv() throws Exception {
assertEquals(2,6 / 3);
assertEquals(new Complex(0,0.5),a.ComplexDiv(c));
assertEquals(new Complex(-0.3,-0.4),b.ComplexDiv(c)); } }
  • 运行截图

(三)重构搭档代码

重构(Refactor),就是在不改变软件外部行为的基础上,改变软件内部的结构,使其更加易于阅读、易于维护和易于变更 。

  • 重构后代码
abstract class Data {
abstract public void DisplayValue();
}
class Integer extends Data {
int value;
Integer() {
value=100;
}
@Override
public void DisplayValue(){
System.out.println (value);
} @Override
public String toString() { //重构
return "value=" + value ;
}
}
class Byte extends Data { byte value;
Byte() {
value=1;
}
@Override
public void DisplayValue(){
System.out.println (value);
} @Override
public String toString() { //重构
return "value=" + value ;
} }
// Pattern Classes
abstract class Factory {
abstract public Data CreateDataObject();
} class IntFactory extends Factory {
@Override
public Data CreateDataObject(){
return new Integer();
}
}
class ByteFactory extends Factory {
@Override
public Data CreateDataObject(){
return new Byte();
}
}
//Client classes
class Document {
private Data pd;
Document(Factory pf){
pd = pf.CreateDataObject();
}
public void getPd() { //重构
pd.DisplayValue();
} public void setPd(Data pd) { //重构
this.pd = pd;
} }
//Test class
public class MyDoc {
static Document d;
public static void main(String[] args) {
d = new Document(new ByteFactory());
d.getPd(); //重构
}
}
  • 运行截图

(四)以结对的方式完成Java密码学相关内容的学习,结合重构、git、代码标准等

  • RSA
import java.security.*;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
import java.security.interfaces.*;
import java.math.*;
import java.io.*;
public class Enc_RSA{
public static void main(String args[]) throws Exception{
String s="Hello World!";
// 获取公钥及参数e,n
FileInputStream f= getFileInputStream();
ObjectInputStream b= getObjectInputStream(f);
RSAPublicKey pbk=(RSAPublicKey)b.readObject( );
BigInteger e= getPublicExponent(pbk);
BigInteger n= getModulus(pbk);
getPrintln("e= " + e);
getPrintln("n= "+n);
// 明文 m
byte ptext[]=s.getBytes("UTF8");
BigInteger m= getBigInteger(ptext);
// 计算密文c,打印
BigInteger c=m.modPow(e,n);
getPrintln("c= "+c);
// 保存密文
String cs=c.toString( );
BufferedWriter out=
new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("Enc_RSA.dat")));
out.write(cs,0,cs.length( ));
out.close( ); } private static BigInteger getBigInteger(byte[] ptext) {
return new BigInteger(ptext);
} private static void getPrintln(String x) {
System.out.println(x);
} private static BigInteger getModulus(RSAPublicKey pbk) {
return pbk.getModulus();
} private static BigInteger getPublicExponent(RSAPublicKey pbk) {
return pbk.getPublicExponent();
} private static ObjectInputStream getObjectInputStream(FileInputStream f) throws IOException {
return new ObjectInputStream(f);
} private static FileInputStream getFileInputStream() throws FileNotFoundException {
return new FileInputStream("Skey_RSA_pub.dat");
}
}

三、实验遇到的问题

  • 问题1:在创建的新的项目里,Junit测试失败,显示Class not found
  • 问题1解决方案:通过查询博客,找到了解决方法,步骤如下:
  1. 按ctrl+shift+alt+s,找到modules>path如下选择:
  2. 选project,根据自己的需要设置output文件夹:
  • 问题2:如何将学习搭档加入到自己的项目中?
  • 问题2解决方案:
  1. 先新建共同的项目,点开项目
  2. 找到管理的选项,点击添加项目成员
  3. 将搭档作为开发者添加

四、PSP时间

步骤 耗时 百分比
   |需求分析           |   30min           | 12%            |
| 设计 | 40min | 15% |
| 代码实现 | 90min | 34% |
|测试 | 45min | 17% |
|分析总结 | 60min |23% |

六、代码链接

https://gitee.com/tiankunye/tky-lxs-program/tree/master/src

七、参考资料

20165230 《Java程序设计》实验三 敏捷开发与XP实践 实验报告的更多相关文章

  1. 20145308刘昊阳 《Java程序设计》实验三 敏捷开发与XP实践 实验报告

    20145308刘昊阳 <Java程序设计>实验三 敏捷开发与XP实践 实验报告 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 统计的PSP(Personal ...

  2. 20155207王雪纯 《Java程序设计》实验三 敏捷开发与XP实践 实验报告

    20155207王雪纯 <Java程序设计>实验三 敏捷开发与XP实践 实验报告 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 统计的PSP(Personal ...

  3. 2016-2017-2 20155339 《Java面向对象程序设计》实验三敏捷开发与XP实践实验报告

    2016-2017-2 20155339 <Java面向对象程序设计>实验三敏捷开发与XP实践实验报告 实验内容 XP基础 XP核心实践 相关工具 实验内容 一.在IDEA中使用工具(Co ...

  4. 20162311 实验三 敏捷开发与XP实践 实验报告

    20162311 实验三 敏捷开发与XP实践 实验报告 实验内容 一.研究学习IDEA中的Code菜单 使用Code ->Reformate Code功能将以下代码格式化 public clas ...

  5. 20165308实验三 敏捷开发与XP实践实验报告

    实验三 敏捷开发与XP实践实验报告 实验目的 安装 alibaba 插件,解决代码中的规范问题.再研究一下Code菜单,找出一项让自己感觉最好用的功能. 在码云上把自己的学习搭档加入自己的项目中,确认 ...

  6. 20155220 实验三 敏捷开发与XP实践 实验报告

    20155220 实验三 敏捷开发与XP实践 实验报告 实验内容 XP基础 XP核心实践 相关工具 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim ...

  7. # 20155224 实验三 敏捷开发与XP实践 实验报告

    20155224 实验三 敏捷开发与XP实践 实验报告 实验内容 XP基础 XP核心实践 相关工具 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim ...

  8. 20155226 实验三 敏捷开发与XP实践 实验报告

    20155226 实验三 敏捷开发与XP实践 实验报告 实验内容 XP基础 XP核心实践 相关工具 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim ...

  9. 20155311 实验三 敏捷开发与XP实践 实验报告

    20155311 实验三 敏捷开发与XP实践 实验报告 实验内容 XP基础 xp核心工具 相关工具 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim ...

随机推荐

  1. 原生Ajax函数

    前言 在日常工作中,我经常使用Jquery的Ajax来获取接口数据.这几天有一个的官网要制作,由于网站比较小,有一些与服务器通信的接口处理,并没有涉及到复杂的交互功能.为了可以减少加载Jquery库的 ...

  2. BZOJ3252 攻略(贪心+dfs序+线段树)

    考虑贪心,每次选价值最大的链.选完之后对于链上点dfs序暴力修改子树.因为每个点最多被选一次,复杂度非常正确. #include<iostream> #include<cstdio& ...

  3. linux shell 执行命令顺序

    1.shell命令搜索顺序 在linux shell 中输入一个命令,如果有多个同名指令,shell需要按照一定规则去取优先级高的一个执行,shell命令的搜索顺序为: 1.别名,使用alias创建的 ...

  4. Oracle 双字段过滤

    白名单:数据 id ,  g_id,sys_id 1,2,3 1,2,4   黑名单:数据 id ,  g_id,sys_id b,2,3   结果  1,2,4      select t1.*   ...

  5. 【刷题】COGS 2701 动态树

    ★★★☆ 输入文件:dynamic_tree.in 输出文件:dynamic_tree.out 简单对比 时间限制:1 s 内存限制:256 MB [题目描述] 开始时有n个点形成的森林,共m个操作. ...

  6. 【bzoj2154】 Crash的数字表格

    http://www.lydsy.com/JudgeOnline/problem.php?id=2154 (题目链接) 题意 给出${n,m}$,求$${\sum_{i=1}^n\sum_{j=1}^ ...

  7. Windows Shell远程执行代码漏洞((CVE-2018-8414)复现

    0x00   SettingContent-ms文件介绍 .SettingContent-ms是在Windows 10中引入的一种文件类型,它的内容是XML格式进行编写的,主要用于创建Windows设 ...

  8. 单点登录(十)-----遇到问题-----cas启用mongodb验证方式报错com.mongodb.CommandFailureException---Authentication failed

    cas启用mongodb验证方式报错com.mongodb.CommandFailureException---Authentication failed. 完整报错信息: 二月 08, 2017 5 ...

  9. %1$s %1$d Android string (java & Android 格式化字符串)

    1$s // String%1$d // int //R.string.old:<string name="old">我今年%1$d岁了</string> ...

  10. 850. 矩形面积 II

    我们给出了一个(轴对齐的)矩形列表 rectangles . 对于 rectangle[i] = [x1, y1, x2, y2],其中(x1,y1)是矩形 i 左下角的坐标,(x2,y2)是该矩形右 ...