第五周作业

20162324 2006-2007-2 《程序设计与数据结构》第5周学习总结

教材学习内容总结

  • 本周要学习的就是有关面向对象的一些知识点:
    面向对象是一种方法,而不是一种编程语言,是一种编程方法;他的终极目标是消除程序中的重复代码,满足DRY(don't reaptyourself)原则。
    对于思维方式来说就是先抽象后具体,先整体后局部,先确定谁来做后确定怎么做。

  • 其次我学习了有关类的相关知识,例如类由类名、属性(成员变量)、方法(成员函数)组成。

教材学习中的问题和解决过程

  • 问题1问题:
    对于书中程序5.2的理解问题。

  • 问题1解决方案:因为5.2中涉及的内容比较的多,包含了很多的本章的其他小节的内容,列如resturn这知识点到5.4节中才介绍到了,当时就没有注意到这一点,就在这个程序上卡了比较长的时间,浪费了一点时间。

  • 问题2:对程序5.5中的新运算符的理解在书中有这么一个表达式:

  • 问题2解决方案:我在附录D Java运算符中找到了这个运算符:“ ?: ” 附录中说它是条件运算符,布尔表达式?表达式一:表达式二,当结果为true时就执行表达式一,当结果为false是就执行表达式二。

代码调试中的问题和解决过程

  • 问题1:
    在这周刚刚开始时我就去完成pp7.5在这过程中要求输入少于50的任意数量的数,求平均值与方差。我建立了一个循环输入一个数就算一次平均值与方差,我就想把最后求均值与方差的的表达式子放在最后,结束循环后再算,发现我在循环中计算出的总数,记录的次数都无法在循环外使用。
    -问题一解决方案:
    我在改变思路之后就发现我可以现把数存入数组,后再求和求平均值,就写出来了这样一程序:

import java.util.Scanner;

public class Average752

{

    public static void main (String[] args)

    {

        Scanner s = new Scanner(System.in);

        Scanner n = new Scanner(System.in);

        String again ="y";

        while(again.equalsIgnoreCase("y"))

        {

            System.out.println("How many number do you want to enter???(Less than 50)");

            int size = s.nextInt();

            int position =0;

            double doublenum [] = new double[size];

            System.out.println("Enter "+ size + " numbers");

            for(int times=1;times <= size ; times++)

            {

                double enter = s.nextDouble();

                doublenum[position] = enter;

                position++;

            }

            System.out.println();

            System.out.println("MEAN");

            double total =0;

            position =0;

            while(position<size)

            {

                total=total+ doublenum[position];

                position++;

            }

            System.out.println(total / size);

            System.out.println();

            System.out.println("sd");

            double mean = total/size;

            while(position<size)

            {

                total = total+(doublenum[position]-mean);

                position++;

            }

            double sd = Math.sqrt((Math.pow(total,2))/(size -1));

            System.out.println(sd);

            System.out.println("Do you want to try again?(y/n)");

            again=n.nextLine();

        }

    }

}



## [代码托管](链接)
- 代码提交过程截图:
 ![](http://images2015.cnblogs.com/blog/1062696/201704/1062696-20170402171729977-81261280.png)
 ![](http://images2015.cnblogs.com/blog/1062696/201704/1062696-20170402171757695-1636389579.png)
 ![](http://images2015.cnblogs.com/blog/1062696/201704/1062696-20170402171829383-87533720.png)






- 代码量截图:
 ![](http://images2015.cnblogs.com/blog/1062696/201704/1062696-20170402171846914-1954056048.png)



(statistics.sh脚本的运行结果截图)

## 上周考试错题总结
-It is possible to send in data to a Java program via the command-line.(可以在命令行中给Java程序发送数据)

Java中命令行课同过数组发送数据给Java程序。
- An array declared as an int[] can contain elements of different primitive types.(用int[]声明的数组,元素类型可以是所有基本类型)

在数组中每个数组中只能含有一种数据类型。

-Which of the following lines of code accesses the second element of the first array in a two-dimensional array of integers, numbers,  and stores the result in a variable called num?(下面哪条语句访问了一个整型二维数组numbers的第二个元素,并把值存入num变量中)(B)
A .
num = numbers[1][2];

B .
num = numbers[0][1];

C .
num = numbers.getElement(1, 2);

D .
num = numbers.getElement(0, 1);

E .
none of the above are correct

数组的交表由0开始,就是说第二个数就是角标为1的元素,有因为是二维数组所以第二个元素就是第一个子数组及角标为0,又要赋值给num所以就选择B;

Suppose we have an array of String objects identified by the variable names.  Which of the following for loops will not correctly process each element in the array.(假如我们有一个名为names的String对象数组,下面哪个for循环不能遍历数组中的每一个元素?)

A .
for(int i = 0; i < names.length; i++)
B .
for(String name : names)

C .
for(int i = 0; i < names.length(); i++)

D .
none of these will correctly process each element(以上都不能遍历)
E .
all of these will correctly process each element(以上都能遍历)

确定边界时就及需要用到length但是它的后面没有括号。在做题时没有注意到。

-Which of the statements is true about the following code snippet?(对于下面的代码段,说法正确的是?)

       int[] array = new int[25];
       array[25] = 2;

A .
The integer value 2 will be assigned to the last index in the array.(整数2会赋给数组中最后一个元素)

B .
The integer value 25 will be assigned to the second index in the array.(整数25会赋给数组中的第2个索引)

C .
The integer value 25 will be assigned to the third value in the array. (整数25会赋给数组中的第3个元素)

D .
This code will result in a compile-time error.(代码会产生编译时错误)
E .
This code will result in a run-time error. (代码会产生运行时错误)

对于这个问题我在idea中进行了测试,结果如下图:(在编译时并没有题是错误而是在运行时就提示了错误所以说是运行时的错误。)

![](http://images2015.cnblogs.com/blog/1062696/201703/1062696-20170331214710570-897135579.png)



![](http://images2015.cnblogs.com/blog/1062696/201703/1062696-20170331214733633-17779567.png)



In Java, a boolean expression is limited to having exactly 2 logical operators.(在Java中,布尔表达式中最多有两个逻辑运算符)


在布尔表达式中可以有任意数量的逻辑运算符,收一布尔表达式就可以够复杂的条件。

-Which of the following are examples of invalid string literals?(下面哪个字符串字面量是不合法的?)

A .
“Hello World!”

B .
“4 score and 7 years ago, our forefathers brought forth...”
C .
“z”
D .
“”
E .
none of the above(以上都不对)

在引号中的就是就是字符串,无论是什么都是合法的就算是什么都不放也可以。

## 结对及互评

  与我结对的是张家铖(跟我关系比较好)我们两经常一起学习,水平上来说他比我要高一些,我就是觉得关系好的人之间比较好交流也易于交流,经常一起做作业所以我们彼此之间都指出了很多的问题,在学习过程中他也给了我比较多的建议。
- [参考示例](http://www.cnblogs.com/haoliberale/p/6580822.html#3650972) 

### 点评过的同学博客和代码

- [2312](http://www.cnblogs.com/1zhjch/p/6654130.html)

## 其他(感悟、思考等,可选)

在这周的学习中我将主要精力放在了书上的知识点的理解上,适当的减少了代码,相比于前一周的确减少不少。一点的将书上的之事点吃透,尽量让自己每次看书都有一定的收获,一点点的进步。在学习的过程中我发现了,在别人的引导下更有利于我掌握知识点,在蓝墨云班课中老师发布的资源给了我很大的帮助,我先观看视频之后在学习书上的知识点是就觉得好理解许多,更会想起那个老师在讲课过程中例举的有去的例子,给了我很大的帮助。我也自己在学习过程中有些时候不经意间就错过了比较重要的细节。(自己粗心大意的毛病有一些难改。)


## 学习进度条


|            | 代码行数(新增/累积)| 博客量(新增/累积)|学习时间(新增/累积)|重要成长|
| --------   | :----------------:|:----------------:|:---------------:  |:-----:|
| 目标        | 5000行            |   30篇           | 400小时            |       |
| 第一周      | 77/77          |  1/1         |14/14            |       |
| 第二周      | 331/408          |   1/2          | 16/30             |       |
| 第三周      | 315/723         |  1/3           | 15/45             |       |
| 第四周      | 848/1546        |  2/5          |20/65            |       |
| 第五周      | 959/2505          |  1/6      | 10/75                |       |

尝试一下记录「计划学习时间」和「实际学习时间」,到期末看看能不能改进自己的计划能力。这个工作学习中很重要,也很有用。
耗时估计的公式
:Y=X+X/N ,Y=X-X/N,训练次数多了,X、Y就接近了。

参考:[软件工程软件的估计为什么这么难](http://www.cnblogs.com/xinz/archive/2011/04/05/2005978.html),[软件工程 估计方法](http://www.cnblogs.com/xinz/archive/2011/04/06/2007294.html)

- 计划学习时间:15小时

- 实际学习时间:10小时

- 改进情况:

(有空多看看[现代软件工程 课件 
软件工程师能力自我评价表](http://www.cnblogs.com/xinz/p/3852177.html))


## 参考资料

-  [《Java程序设计与数据结构教程(第二版)》](https://book.douban.com/subject/26851579/)

-  [《Java程序设计与数据结构教程(第二版)》学习指导](http://www.cnblogs.com/rocedu/p/5182332.html)

posted on 2017-04-02 17:53  20162324-春旺  阅读(237)  评论(7编辑  收藏  举报

导航