20165324 Java实验三 敏捷开发与XP实验
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

任务三:下载搭档的代码,至少进行三项重构
- 重构内容
Rename可以给类、包、方法变量改名字。- 封装类,还可以封装成员变量。
- 避免代码重复,打印信息
System.out.println();可通过toString方法重构。
- 重构动机:
- 增加新功能;
- 原有功能有BUG;
- 改善原有程序的结构;
- 优化原有系统的性能 。
- 重构手法:

本次重构内容
- 将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与密码学的小结合。
四、参考资料
20165324 Java实验三 敏捷开发与XP实验的更多相关文章
- 实验三 敏捷开发和XP实验
课程:Java程序设计实验 班级:1352 姓名: 于佳心 学号:20135206 成绩: 指导教师:娄嘉鹏 ...
- 20145213《Java程序设计》实验三敏捷开发与XP实践
20145213<Java程序设计>实验三敏捷开发与XP实践 实验要求 1.XP基础 2.XP核心实践 3.相关工具 实验内容 1.敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法 ...
- 20145308刘昊阳 《Java程序设计》实验三 敏捷开发与XP实践 实验报告
20145308刘昊阳 <Java程序设计>实验三 敏捷开发与XP实践 实验报告 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 统计的PSP(Personal ...
- JAVA课程实验报告 实验三 敏捷开发与XP实践
北京电子科技学院(BESTI) 实 验 报 告 课程:Java程序设计 班级:1353 姓名:韩玉琪 学号:20135317 成绩: 指导教师:娄嘉 ...
- 20145225《Java程序设计》 实验三 "敏捷开发与XP实践"
20145225<Java程序设计> 实验三 "敏捷开发与XP实践" 实验报告 实验内容 使用 git 上传代码 使用 git 相互更改代码 实现代码的重载 git 上 ...
- 2018-2019-20175205 实验三敏捷开发与XP实践《Java开发环境的熟悉》实验报告
2018-2019-20175205 实验三敏捷开发与XP实践<Java开发环境的熟悉>实验报告 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)>&l ...
- 20155324 《Java程序设计》实验三 敏捷开发与XP实践
20155324 <Java程序设计>实验三 敏捷开发与XP实践 实验内容 XP基础 1.XP核心实践 2.相关工具 实验步骤 敏捷开发与XP 1.敏捷开发(Agile Developme ...
- 20165205 2017-2018-2 《Java程序设计》实验三 敏捷开发与XP实践
20165205 2017-2018-2 <Java程序设计>实验三 敏捷开发与XP实践 实验内容 检查点1: 安装alibaba 插件,解决代码中的规范问题 首先把搭档加入到自己的项目中 ...
- 2018-2019-2 20175306实验三敏捷开发与XP实践《Java开发环境的熟悉》实验报告
2018-2019-2 20175306实验三敏捷开发与XP实践<Java开发环境的熟悉>实验报告 实验内容 XP基础 XP核心实践 相关工具 实验要求 1.没有Linux基础的同学建议先 ...
随机推荐
- C++ 类的抽象初练
/* 某商店经销一种货物,货物的购进和卖出以箱为单位,各箱的重量不一样, 因此商店需要目前库存的总重量. 现在用c++模拟商店货物购进和卖出的情况 */ #include<iostream> ...
- Deep learning for Human Strategic Behaviour
没看,但是论文UI和视频做的很好. 论文地址:https://papers.nips.cc/paper/6509-deep-learning-for-predicting-human-strategi ...
- csdn 模式识别
http://blog.csdn.net/liyuefeilong/article/details/45217335 模式识别 http://ceit.ucas.ac.cn/index.php?id= ...
- 【BZOJ】1016: [JSOI2008]最小生成树计数(kruskal+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1016 想也想不到QAQ 首先想不到的是:题目有说,具有相同权值的边不会超过10条. 其次:老是去想组 ...
- exif_imagetype() 函数在linux下的php中不存在
1.问题,项目中上传文件使用插件时,windows上支持函数exif_imagetype(),而在linux上不支持. 2.PHP exif_imagetype的本质 PHP exif_imagety ...
- Spring Boot注解(annotation)列表
(1)@SpringBootApplication 申明让spring boot自动给程序进行必要的配置,这个配置等同于: @Configuration ,@EnableAutoConfigurati ...
- xdebug常用配置
;指定xdebug文件 zend_extension = "F:\tools\develop_tools\php\php_xdebug-2.2.2-5.4-vc9.dll" ;xd ...
- Angular2 HttpClient (一)
@angular/common/http 中的 HttpClient 类为 Angular 应用程序提供了一个简化的 API 来实现 HTTP 客户端功能.它基于浏览器提供的 XMLHttpReque ...
- js获取表单数据
var modelObj = {}; var modelFieldsArray = $('#AddMusicCategory').serializeArray(); $.each(modelField ...
- IOC和AOP的一些基本概念
IOC和AOP的一些基本概念介绍 IOC 介绍 IOC 一.什么是IOC IoC就是Inversion of Control,控制反转.在Java开发中,IoC意味着将你设计好的类交给系统去控制,而不 ...