[软件构造]Lab1 一个报告

Day1

Magic Squares
  • 应该是 面向过程 + 测试优先
  • 可供选择的数据结构是
  • (这个要好好挑一挑)
  • 过程的一些规约
  1. 文件的输入 ,转化成我们需要的数据结构
  2. 在这个数据结构上,进行相关的操作
  • 也借此机会建构一下相关的知识

Java 中二维数组的实现方式

  • 数组的数组实现
    http://c.biancheng.net/view/916.html
异常处理的内容

先空过去

Req 2
  • 实际上把 1~ nn 这么nn个数 填到n*n的表中,具体怎么填呢?
  • row从0开始 填够一行 每次加1
Part 2 Problem 3 Turtle graphics and drawSquare 题目的翻译
  • 英语太多了 ,只能这样慢慢看来,tnnd.
  • 首先克服语言障碍。果然,我校的英语教育通过专业课完成。 希望今年6月6级能有580.
  • forward(units)前进(单位)
    Moves the turtle in the current direction by units pixels, where units is an integer. Following the original Logo convention, the turtle starts out facing up.
    移动小海龟通过单位像素(pixels),这里单位为整数。遵从一个古老的惯例,小海龟开始的时候面是朝上的。
    turn(degrees)旋转(角度)
    Rotates the turtle by angle degrees to the right (clockwise), where degrees is a double precision floating point number.
    向右旋转一定的角度(by angle degree)小海龟(clockwise顺时针),这里角度为double双精度类型。

You can see the definitions of these commands in Turtle.java.

Now look at the source code in TurtleSoup.java, in the src folder in package turtle.

  • Your first task is to implement drawSquare(Turtle turtle, int sideLength), using the two methods introduced above: forward and turn.

  • 我们的第一个task是(终于到了 废话真多)实现drawSquare(Turtle tirtle,int sideLengh),使用上面(above)介绍的两个方法: forward 和turn.

  • Once you’ve implemented the method, run the main method in TurtleSoup.java. To run main, right-click on the file TurtleSoup.java in the Package Explorer on the left side of Eclipse, go to Run As, and select Java Application.

  • 一旦(once)我实现了这个method,在
    TurtleSoup.java里运行main()方法,…(对如何运行的步骤的介绍blablabla)

  • This main method creates a new turtle, calls your drawSquare method, and instructs the turtle to draw on screen. A window will pop up, and, once you click the “Run!” button, you should see a square drawn on the canvas.

  • main()干了啥 main*() new了一个turtle对象,call了drawAquare方法,instructs这个tutle画在屏幕上。这个时候,一个windows就会pop up(突然出现),一旦我点了"Run!"按钮,我就会在画布上看见一个方块画在canvas(板子上一个绘画软件也叫这个名)

  • 好的现在题看明白了 研究研究吧

Par3 Problem3 的Report
Turtle到底是个啥?
  • 这个turtle是不是小海龟的意思,感觉更像是pointer呀
  • n. 海龟;海龟肉;<美>龟;淡水龟;(计算机)龟标 好吧百度一下龟标是啥
    https://zhuanlan.zhihu.com/p/67397220 好吧确实是个pointer 不过是个turtle样子的
先运行一下试试看
  • 首先要在eclipse中打开我们的文件。
  • file->import ->general->exciting …->YES
  • 这就是test first的编程思想呗。
  • 我# 这么高级吗 ,这也太有意思了点吧。
Part 3

Implement and test a FriendshipGraph class that represents friendships in a
social network and can compute the distance between two people in the graph. An auxiliary class Person is also required to be implemented.

  • 实现FriendshipGraph 类,这玩意代表社交网络中的友谊,还能计算图里头两人的距离。
  • 辅助(auxiliary)的类Person也得实现
  • Ctrl + Shift + F to auto-format your code!
  • 这么好的吗 自动格式化代码
  • 这个就需要一些基础的OOP概念了。
OOP+构造方法
  • 要选择一下用什么数据结构,还有应该给Person给个ID

  • 然后 拿三元组存储边吧

  • 不需要 拿着ID 找person

  • 所以不需要数据库

  • 就三元组就行 实现的话 用ArrayList+自定义数据类型(对象实现)好的

  • 以邻接链表存也行 宽搜 需要列表 会更方便

  • x现在基本完成了 下面需要做一些测试。

TIPs in Java

数组赋初值 不要用 增强循环 会不成功的。

应该Test的部分还是没有完成的

Day2

Java 题目

  • Given an array if citataions of a researcher,write a function to computer the research’s h-index.
  • A sicientist has index h if h of his/her N papers have at least h citations(N篇论文中的h篇每个至少有h引用),and the other N-h papers have no more than h citations each.(剩下的N-h篇论文每个的引用数不超过h)

编写代码

  • 从控制台读入的代码块

健壮性处理

将计算功能与用户输入分离开来

编写测试用例 junit的使用

Tips

project的文件结构

  • 与梳理project结构相关的问题(Eclipse的使用的问题)

  • Build path的问题

  • 在src文件夹上点右键-Build Path-Use as Source Folder,重新进行编译,一切正常了

  • Run configuration的问题

  • 异常处理

  • 相较C语言程序不得不考虑的问题

  • 解决方法

  • 每次修改 源路径 Source Folder只能有一个 对应一个main class为 src/P1

  • 然后设置Run as 主类 在项目内搜索

  • refresh很好用

相对路径

* isLegalMagicSquare("src/txt/1.txt");

异常处理

  • 这个re-throw IOexception 是哪个意思吗?
  • 这个编译器好像帮我们干了。
  • 应该就是我们在合适的时候抛出异常即可,剩下的编译器会帮我们干的。
  • 然后鼠标放在我们掉的库函数上,就会有显示 异常 的规约信息。
  • 规约里有会throw什么异常信息的。

未完成的工作

  • P3的测试代码
  • 实验报告书写
  • 还要把代码和同学们对对,要求太多了,不一定能看全。

convex hull

gift-wrappint algorithm

  • 我们来翻译一下wiki的内容
  • 这个时候我的心里有一百个不情愿。
  • computing the convex hull of a given set of points.
  • convex hull
  • 请添加图片描述
  • Animation of the gift wrapping algorithm. The red lines are already placed lines, the Black line is the current best guess for the new line, and the green line is the next guess

Palnar case 平面的情况

  • for the sake of simplicity 为简单起见
  • 直接看algorithm 不管为什么了
    *The gift wrapping algorithm begins with i=0 and a point p0 known to be on the convex hull, e.g., the leftmost point,
    *and selects the point pi+1 such that all points are to the right of the line pi pi+1.
    *This point may be found in O(n) time by comparing polar angles of all points with respect to point pi taken for the center of polar coordinates.
    *Letting i=i+1, and repeating with until one reaches ph=p0 again yields the convex hull in h steps. In two dimensions, the gift wrapping algorithm is similar to the process of winding a string (or wrapping paper) around the set of points.
    *算法开始
    (1)i=0 必在凸包内的点p_0 (比如最左边的那个点)
    (2)选择点P_i,保证所有的点都在 边P_i P_I+1的右边
    * 这个点再O(n)内被找到,通过比较 各点相对pi为极点的极坐标的极角。
    * with respect to 相对
    * the center of polar coordinates极坐标的中西点
    (3)令i=i+1 重复知道p_h(最新确定的点)=p_0(最早确定的点)
    * form = yield =constuct =generate
  • 在二维空间。包礼物算法,类似于在点集外圈一个圈(wind a string)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值