20172325 2016-2017-2 《Java程序设计》第四周学习总结
教材学习内容总结
1.对类、对象、声明变量的定义和属性有了进一步的了解
2.学会如何编写一个类并运用到需要的程序中
3.学习了形参和实参的概念和区别
4.修饰符的作用和运用,例如public和private
5.学习了静态类,例如静态方法和静态变量
6.关于封装的作用和运用
7.在面向对象的程序设计时需要做的必要步骤,包括需求、设计、实现和测试
8.对枚举类的进一步了解
9.学习了调用方法中的方法重载
10.UML类图包含的内容和作用,有助于对类的理解
教材学习中的问题和解决过程
- 问题1:区分不了对象和类
- 问题1解决方案:首先是通过学习教材了解具体定义,然后百度具体区别,然后通过具体操作加深理解。下面是自己的理解,类是一个规则一个标准或者说一个模范,是一个虚拟的存在;对象是一个可变的的个体,有具体的需求和形态。而对象和类的联系在于对象的实现需要通过类来规范。
- 问题2:在形参和实参的理解和运用上很头疼
- 问题2解决方案:之前是在网上查询,可以参考这篇博客[(https://www.cnblogs.com/calence/p/5346672.html)]
后来老师在课上也给出了很详细的讲解。
代码调试中的问题和解决过程
- 问题1:对于getFaceValue和setFaceValue的作用不是很清楚,在敲例题4.2的时候,中间加了这两个方法和删除之后运行没有差别,不知道为何。
- 问题1解决方案:通过看书以后了解到,他们是同级的不同调用方法,内容不一样而已,这就是在设计时输入get和set先后顺序对于结果没有影响
- 问题2:如下图,不知道是什么情况,自从出现了这个东西,试了之前编译运行成功的程序也出现这样的结果。
代码托管
上周考试错题总结
- 1.In Java a variable may contain
A a value or a reference
B a package
C a method
D a class
E any of the above
在JAVA中变量只能包含一个值或一个引用。所以应该选a的。
- 2.If two variables contain aliases of the same object then
A the object may be modified using either alias
B the object cannot be modified unless there‘s but a single reference to it
C a third alias is created if/when the object is modified
D the object will become an "orphan" if both variables are set to null
E answers A and D are correct
对象可以使用别名进行修改,如果两个变量都设置为null,那么对象将变成一个“孤儿”。
- 3.Which properties are true of String objects?
A Their lengths never change
B The shortest string has zero length
C Individual characters within a String may be changed using the replace method
D The index of the first character in a string is one
E Only A and B are true
他们的长度永远不会改变,最短的字符串长度为零。字符串是不可变的。这意味着, 一旦创建了字符串对象, 就不能更改它。因此, 字符串的长度在创建后不会更改。最短长度字符串为 "", 引号之间没有字符, 因此长度为零。
- 4.What happens if you attempt to use a variable before it has been initialized?
A A syntax error may be generated by the compiler
B A runtime error may occur during execution
C A "garbage" or "uninitialized" value will be used in the computation
D A value of zero is used if a variable has not been initialized
E Answers A and B are correct
编译器多次能够检测到未初始化变量的尝试使用, 在这种情况下会产生语法错误。如果编译器使用转义检测, 则在使用时会发生运行时错误。
- 5.What is the function of the dot operator?
A It serves to separate the integer portion from the fractional portion of a floating point number
B It allows one to access the data within an object when given a reference to the object
C It allows one to invoke a method within an object when given a reference to the object
D It is used to terminate commands (much as a period terminates a sentence in English)
E Both B and C are correct
点算符的功能为:它允许在给定对象的引用时访问对象中的数据,当给定对象的引用时,它允许在对象中调用方法。所以这道题应该选e的。
- 6.Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length( ), in order to use the Math class, you pass messages directly to the class name, as in Math.abs( ) or Math.sqrt( ).
A .true
B .false
数学类使用被称为静态方法 (或类方法) 的方法, 通过将消息直接传递到类名本身而不是类的对象来调用。
- 7.Which of the following will yield a pseudorandom number in the range [ -5, +5 ) given the following:
Random gen = new Random( );
A . gen.nextFloat( ) * 5
B . gen.nextFloat( ) * 10 - 5
C . gen.nextFloat( ) * 5 - 10
D . gen.nextInt( ) * 10 - 5
E . gen.nextInt(10) - 5
gen.nextInt(10) - 5 所得到的结果是-5,-4,-3,-2,-1,0,1,2,3,4,并不是题目中所要求的,它得到的只是一些数而不是一个取值范围。而nextFloat则是在范围[0,1)中产生伪随机数字;乘以10的收益率在0到10之间,再减去5,得到结果。
- 8.Consider the following two lines of code. What can you say about s1 and s2?
String s1 = "testing" + "123";
String s2 = new String("testing 123");
A . s1 and s2 are both references to the same String objects
B . the line declaring s2 is legal Java; the line declaring s1 will produce a syntax error
C . s1 and s2 are both references to different String objects
D . s1 and s2 will compare "equal"
E . none of the above
这两个声明都是合法的Java。s1是一个字符串引用,它被初始化为字符串“testing123”。s2是一个字符串引用,它被初始化为字符串“测试123”。注意“测试”和“123”之间的空格。所以这两个字符串不相等。
- 9.An "alias"(别名) is when
A . two different reference variables refer to the same physical object
B . two different numeric variables refer to the same physical object
C . two different numeric variables contain identical values
D . two variables have the same names
E . none of the above
当有两个或多个对同一物理对象的引用时,就会出现“别名”,这样,通过遵循任一引用,就可以读/写/修改对象
- 10.The String class‘ compareTo method
A . compares two string in a case-independent manner(独立的方式)
B . yields (收益率)true or false
C . yields 0 if the two strings are identical
D . returns 1 if the first string comes lexically before the second string
E . none of the above
如果两个字符串是完全一致的,那么它的值为0。
- 11.The advantages of the DecimalFormat class compared with the NumberFormat class include
A precise control over the number of digits to be displayed
B control over the presence of a leading zero
C the ability to truncate values rather than to round them
D the ability to display a % automatically at the beginning of the display
E only A and B
伪随机数生成器相对于Math.random的优势在于:可以创建几个随机数生成器,可以在一个范围内生成随机的int,floats和ints。所以应该包括A与B。
- 12.If you need to import not only the top-level of a package, but all its secondary levels as well, you should write: import package..;
A true
B false
如果您不仅需要导入包的顶层, 而且还要输入所有的辅助级别, 则应编写: 导入包. ;(false);导入包.
- 13.You may use the String replace( ) method to remove characters from a String.
A true
B false
replace()方法仅用其他单个字符替换单个字符。replace()方法不会将字符添加或删除字符串;字符串长度将保持不变
- 14.All the methods in the Math class are declared to be static.
A true
B false
数学类方法被设计成在算术表达式中通常有用,因此不需要任何实例来使用它们。这是通过确保所有的数学方法都是静态的来实现的。
- 15.The advantage(s) of the Random class‘ pseudo-random number generators, compared to the Math.random method, is that
A . you may create several random number generators
B . the generators in Random are more efficient than the one in Math.random
C . you can generate random ints, floats, and ints within a range
D . you can initialize and reinitialize Random generators
E . all but answer B
所有随机数字生成器的效率是一样的。随机生成器优于数学的优点。随机包含所有其他属性。
- 16.The advantages of the DecimalFormat class compared with the NumberFormat class include
A . precise control over the number of digits to be displayed
B . control over the presence of a leading zero
C . the ability to truncate values rather than to round them
D . the ability to display a % automatically at the beginning of the display
E . only A and B
通过一个或多个数学方法,截断在程序员的手中“%”符号会出现在显示器的末端,而不是开始。
原文地址:https://www.cnblogs.com/20172325DYK/p/8719789.html