20165324 Java实验三 敏捷开发与XP实验

一、实验报告封面

课程:Java程序设计 班级:1653班 姓名:何春江 学号:20165324

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

实验时间:13:45 - 15:25 实验序号:24

实验名称:面向对象程序设计

二、实验内容

任务一:在IDEA中使用工具(Code->Reformate Code)格式化代码,并学习Code菜单的功能

知识点总结

  • Code菜单

  • 代码整理得:
public class CodeStandard {
public static void main(String[] args) {
final int m = 20;
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() < m) {
buffer.append("1234567");
}
for (int i = 0; i < buffer.length(); i++) {
System.out.println(buffer.charAt(i));
}
}
}
  • Code菜单使用截图

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

  • 实验截图:

  • 提交上传截图:

  • git log

任务三:下载搭档的代码,至少进行三项重构

  • 重构内容
  1. Rename可以给类、包、方法变量改名字。
  2. 封装类,还可以封装成员变量。
  3. 避免代码重复,打印信息System.out.println();可通过toString方法重构。
  • 重构动机:
  1. 增加新功能;
  2. 原有功能有BUG;
  3. 改善原有程序的结构;
  4. 优化原有系统的性能 。
  • 重构手法:

本次重构内容

  • 将Student类中各定义的变量进行重构
  • 包名,类名的重构
  • 方法的重构
  • 对于输出的重构,因为其输出中存在其他参数,未能成功使用toString()进行重构。
package hcj;
import java.util.Scanner;
public class Test {
public static void main(String args[]) {
System.out.println("输入两个班的人数:");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
Student []stu1=new Student[n];//创建对象数组
Student []stu2=new Student[m];//创建对象数组
Fen(stu1,n);
Fen(stu2,m);
System.out.println("现在输入一班学生信息:");
Input(stu1,n);
System.out.println("现在输入二班学生信息:");
Input(stu2,m);
paixu(stu1,n);
paixu(stu2,m);
System.out.println("一班信息为:");
Output(stu1,n);
System.out.println("二班信息为:");
Output(stu2,m);
}
private static void Fen(Student[] stu, int n) {//分配空间
for (int i=0;i<n;i++) {
stu[i]=new Student();
}
} private static void Input(Student stu[],int n) {//输入
Scanner sc=new Scanner(System.in);
for (int i=0;i<n;i++) {
System.out.println("请按以下格式输入学生信息:姓名 学号 性别 数学成绩 物理成绩");
stu[i].setName(sc.next());
stu[i].setNumber(sc.nextInt());
stu[i].setGender(sc.next());
stu[i].setMathScore(sc.nextInt());
stu[i].setPhyScore(sc.nextInt());
}
}
private static void paixu(Student stu[],int n) {
for (int i=0;i<n-1;i++) {
for (int j=i+1;j<n;j++) {
if (stu[i].getNumber() > stu[j].getNumber()) {
Student s=stu[i];
stu[i]=stu[j];
stu[j]=s;
}
}
}
}
private static void Output(Student stu[],int n) {
for (int i=0;i<n;i++) {
System.out.println("姓名:"+ stu[i].getName() +",学号:"+ stu[i].getNumber() +",性别:"+ stu[i].getGender() +",数学成绩:"+ stu[i].getMathScore() +",物理成绩:"+ stu[i].getPhyScore());
}
}
}
class Student {
private String name;
private int number;
private String gender;
private int mathScore;
private int phyScore; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public int getNumber() {
return number;
} public void setNumber(int number) {
this.number = number;
} public String getGender() {
return gender;
} public void setGender(String gender) {
this.gender = gender;
} public int getMathScore() {
return mathScore;
} public void setMathScore(int mathScore) {
this.mathScore = mathScore;
} public int getPhyScore() {
return phyScore;
} public void setPhyScore(int phyScore) {
this.phyScore = phyScore;
}
}

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

  • 结对编程之实现线性移位寄存器和对偶移位寄存器
  • 初步完整代码如下:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.println("请输入移位寄存器的级数n:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("请设置初态:");
int[] a = new int[n];//状态数
int sum=1;
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
sum=2*sum;
}
System.out.println("请输入结构常数:");//形如[c1,c2,c3,c4,c5]
int[] c = new int[n];//存储的为反馈函数,与反馈函数的对应规律为:若结构常数为[0,1,0,1],则反馈函数为1 0 1 0
for (int i = n-1; i >= 0; i--) {
c[i] = sc.nextInt();
}
System.out.println("线性移位寄存器输出序列为:");
for (int i = 0; i <sum-1; i++) {
System.out.printf("%d", a[0]);
operate1(a, c, n);
}
System.out.println(" ");
System.out.println("对偶移位寄存器输出序列为:");
for(int i=0;i<sum-1;i++) {
System.out.printf("%d",a[0]);
operate2(a,c,n);
}
}
private static int[] operate2(int[] a, int[] c, int n) {
int temp=a[0];
for(int i=0;i<n-1;i++) {
a[i]=a[i+1];
}
a[n-1]=0;
if(temp==1) {
for(int j=0;j<n;j++) {
a[j]=(a[j]+c[n-j-1])%2;
}
}
return a;
}
private static int[] operate1(int[] a, int[] c, int n) {
int temp=0;
for (int i = 0; i < n; i++) {
if (a[i] * c[i] == 1) {
temp += 1;
}
}
a[n - 1] %= 2;
for (int j = 0; j < n - 1; j++) {
a[j] = a[j + 1];
}
a[n-1]=temp;
return a;
}
}
  • 重构之后代码如下:
import java.util.*;
public class Lfsr {
public static void main(String[] args) {
System.out.println("请输入移位寄存器的级数n:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("请设置初态:");
int[] a = new int[n];//状态数
int sum=1;
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
sum=2*sum;
}
System.out.println("请输入结构常数:");//形如[c1,c2,c3,c4,c5]
int[] c = new int[n];//存储的为反馈函数,与反馈函数的对应规律为:若结构常数为[0,1,0,1],则反馈函数为
for (int i = n-1; i >= 0; i--) {
c[i] = sc.nextInt();
}
System.out.println("线性移位寄存器输出序列为:");
for (int i = 0; i <sum-1; i++) {
System.out.printf("%d", a[0]);
operate1(a, c, n);
}
System.out.println(" ");
System.out.println("对偶移位寄存器输出序列为:");
for(int i=0;i<sum-1;i++) {
System.out.printf("%d",a[0]);
operate2(a,c,n);
}
}
private static int[] operate2(int[] a, int[] c, int n) {
int temp=a[0];
for(int i=0;i<n-1;i++) {
a[i]=a[i+1];
}
a[n-1]=0;
if(temp==1) {
for(int j=0;j<n;j++) {
a[j]=(a[j]+c[n-j-1])%2;
}
}
return a;
}
private static int[] operate1(int[] a, int[] c, int n) {
int temp=0;
for (int i = 0; i < n; i++) {
if (a[i] * c[i] == 1) {
temp += 1;
}
}
a[n - 1] %= 2;
for (int j = 0; j < n - 1; j++) {
a[j] = a[j + 1];
}
a[n-1]=temp;
return a;
}
}
  • 重构实现截图

  • 实验截图为:

步骤 耗时 百分比
需求分析 10min 15%
设计 15min 21%
代码实现 20min 28%
测试 15min 21%
分析总结 10min 15%

三、实验体会与总结

结对编程,一起学习了线性移位寄存器和对偶移位寄存器的相关内容,轮换担任了领航员,一起实现了Java与密码学的小结合。

四、参考资料

敏捷开发与XP实践

IDEA插件使用文档

20165324 Java实验三 敏捷开发与XP实验的更多相关文章

  1. 实验三 敏捷开发和XP实验

    课程:Java程序设计实验   班级:1352             姓名: 于佳心           学号:20135206 成绩:               指导教师:娄嘉鹏         ...

  2. 20145213《Java程序设计》实验三敏捷开发与XP实践

    20145213<Java程序设计>实验三敏捷开发与XP实践 实验要求 1.XP基础 2.XP核心实践 3.相关工具 实验内容 1.敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法 ...

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

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

  4. JAVA课程实验报告 实验三 敏捷开发与XP实践

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计  班级:1353  姓名:韩玉琪  学号:20135317 成绩:             指导教师:娄嘉 ...

  5. 20145225《Java程序设计》 实验三 "敏捷开发与XP实践"

    20145225<Java程序设计> 实验三 "敏捷开发与XP实践" 实验报告 实验内容 使用 git 上传代码 使用 git 相互更改代码 实现代码的重载 git 上 ...

  6. 2018-2019-20175205 实验三敏捷开发与XP实践《Java开发环境的熟悉》实验报告

    2018-2019-20175205 实验三敏捷开发与XP实践<Java开发环境的熟悉>实验报告 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)>&l ...

  7. 20155324 《Java程序设计》实验三 敏捷开发与XP实践

    20155324 <Java程序设计>实验三 敏捷开发与XP实践 实验内容 XP基础 1.XP核心实践 2.相关工具 实验步骤 敏捷开发与XP 1.敏捷开发(Agile Developme ...

  8. 20165205 2017-2018-2 《Java程序设计》实验三 敏捷开发与XP实践

    20165205 2017-2018-2 <Java程序设计>实验三 敏捷开发与XP实践 实验内容 检查点1: 安装alibaba 插件,解决代码中的规范问题 首先把搭档加入到自己的项目中 ...

  9. 2018-2019-2 20175306实验三敏捷开发与XP实践《Java开发环境的熟悉》实验报告

    2018-2019-2 20175306实验三敏捷开发与XP实践<Java开发环境的熟悉>实验报告 实验内容 XP基础 XP核心实践 相关工具 实验要求 1.没有Linux基础的同学建议先 ...

随机推荐

  1. 用 free 或 delete 释放了内存之后,立即将指针设置为 NULL,防止产 生“野指针”

    用 free 或 delete 释放了内存之后,立即将指针设置为 NULL,防止产 生“野指针”. #include <iostream> using namespace std; /* ...

  2. 【POJ】1523 SPF(割点)

    http://poj.org/problem?id=1523 太弱... too weak.. 割点我都还要看书和看题解来写..果然是写不出么.. 割点就那样求,然后分量直接这个节点有多少子树就有子树 ...

  3. 《Java并发编程实战》第八章 线程池的使用 读书笔记

    一.在任务与运行策略之间的隐性解耦 有些类型的任务须要明白地指定运行策略,包含: . 依赖性任务.依赖关系对运行策略造成约束.须要注意活跃性问题. 要求线程池足够大,确保任务都能放入. . 使用线程封 ...

  4. Spring_day03--Spring的事务管理

    Spring的事务管理 事务概念 1 什么事务 事务是操作中最基本的单元,表示一组操作要么都成功,有一个失败那么所有都失败. 2 事务特性 原子性 一致性 隔离性 持久性 3 不考虑隔离性产生读问题 ...

  5. 数据库布尔型状态字段互斥性的SQL更新操作

    一个配置表或者一个存储了多条状态的表,需要在某个状态中做切换,而当前是否启用状态标记是用0和1来标识的.这个时候通常 1表示正在使用中,0表示不在使用中.通常有些业务会做一些配置的状态切换,就会出现要 ...

  6. eq与gt的妙用

    应用到jq中: 一.jquery  :gt选择器: 定义:   :gt 选择器选取 index 值高于指定数的元素. 语法:$(":gt(index)") ex:$("l ...

  7. eclipse 的代码着色插件 --Eclipse Color Theme

    Eclipse Color ThemeEclipse自带的背景颜色是白色的,很伤眼睛,故而安装一个颜色和主题插件,来改变代码区域的背景颜色以及关键字的颜色. 网址:http://eclipsecolo ...

  8. ECharts使用(1)(转载)

    转载自http://www.cnblogs.com/Olive116/p/3634480.html 1.  EChart最新的文档目录. 首先创建一个解决方案,目录如下: 之前的一篇文章中讲到如果要使 ...

  9. Python--进阶处理1

    # ===============Python 进阶======================= # ---------第一章:数据结构和算法----------- # ----------解压序列 ...

  10. iass,pass,cass,sass,vm,container

    分布式存储hdfs 大文件,swift 对象存贮. 为七牛的CDN系统目前大部分还不是自建的,采用的是整合其它CDN的方式做的.也就是说出了七牛的文件分发使用的是网宿和蓝汛的老牌CDN的分发节点,自身 ...