关键词不能为空

当前您在: 主页 > 英语 >

Exam(Ch8, 9, 10)

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-09 22:19
tags:

-

2021年2月9日发(作者:赞助商英文)


Name:_______________________


Covers Chapters 8-10


CSCI 1302 OO Programming


Armstrong Atlantic State University


50 min


Instructor: Y. Daniel Liang



Part I. (2 pts each)



1.


What is wrong in the following code?




class


Test {



public static void


main(String[] args) {


A a =


new


A();


();


}


}



class


A {


String s;



A(String s) {



this


.s = s;


}




public void


print() {


(s);


}


}






2.


What is the printout of the following code?



public class


Foo {



private boolean



x;




public static void


main(String[] args) {


Foo foo = new Foo();


n(foo.x);


}


}






3.


Show the output of the following program:




public class


Test {



public static void


main(String[] args) {


public class


Count {



public int


count;


Count myCount =


new


Count();




int


times =


0


;


Count(


int


c) {



count = c;



for


(


int


i =


0


; i <


100


; i++)


}


increment(myCount, times);




Count() {


n(



+ );


count =


1


;


n(



+ times);


}


}


}




public static void


increment(Count c,


int


times) {


++;


times++;


}


}







1



4. Show the output of the following program when invoked


using




java Test I have a dream



public class


Test {



public static void


main(String[] args) {


n(



+ );



for


(


int


i =


0


; i < i++)


n(args[i]);


}


}









Part II:


a. (15)


(Geometry: The MyRectangle2D class) Define the


MyRectangle2D class that contains:


?



Two double data fields named x and y that specify the


center of the rectangle with get and set methods.


(Assume that the rectangle sides are parallel to x- or


y- axes.)


?



The double data fields width and height with get and


set methods.


?



A no-arg constructor that creates a default rectangle


with (0, 0) for (x, y) and 1 for both width and


height.


?



A constructor that creates a rectangle with the


specified x, y, width, and height.


?



A method getArea() that returns the area of the


rectangle.


?



A method getPerimeter() that returns the perimeter of


the rectangle.


?



A method contains(double x, double y) that returns


true if the specified point (x, y) is inside this


rectangle. See Figure 1(a).


?



A method contains(MyRectangle2D r) that returns true


if the specified rectangle is inside this rectangle.


See Figure 1(b).



2


?



A method overlaps(MyRectangle2D r) that returns true


if the specified rectangle overlaps with this


rectangle. See Figure 1(c).






p



(a) (b) (c)






Figure 1


(a) A point is inside the rectangle. (b) A rectangle


is inside another rectangle. (c) A rectangle overlaps


another rectangle.



Draw the UML diagram for the class.



Implement the method getArea(), getPerimeter(),


contains(double x, double y), contains(MyRectangle2D


r), and overlaps(MyRectangle2D r).









3


This page is left blank intentionally.



4


2. (10 pts)


(


Occurrences of a specified character


) Write


a method that finds the number of occurrences of a


specified character in the string using the following


header:



public static int


count(String str,


char


a)



For example, count(


program that prompts the user to enter a string


and a character and displays the number of


occurrences of the character in the string.








5


Part III: Multiple Choice Questions: (1 pts each)


(Take the multiple-choice questions online from LiveLab.


Log in and click Take Instructor Assigned Quiz. You have to


take it before it is due. You have to submit within the


specified time interval.)




6


1.


Analyze the following code:



public class Test {


private int t;



public static void main(String[] args) {


int x;


n(t);


}


}


A. The program compiles and runs fine.


B. The variable t is private and therefore cannot be accessed in the main method.


C. The variable x is not initialized and therefore causes errors.


D. t is non-static and it cannot be referenced in a static context in the main method.


E. The variable t is not initialized and therefore causes errors.


Key:D



#


2.


________ is invoked to create an object.


A. The main method


B. A method with a return type


C. A method with the void return type


D. A constructor


Key:D



#


3


. Given the declaration Circle x = new Circle(), which of the following statement is most


accurate.


A. x contains an object of the Circle type.


B. You can assign an int value to x.


C. x contains a reference to a Circle object.


D. x contains an int value.


Key:C



#


4.


Analyze the following code.



public class Test {


int x;



public Test(String t) {


n(


}



public static void main(String[] args) {



7

-


-


-


-


-


-


-


-



本文更新与2021-02-09 22:19,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/624395.html

Exam(Ch8, 9, 10)的相关文章

  • 余华爱情经典语录,余华爱情句子

    余华的经典语录——余华《第七天》40、我不怕死,一点都不怕,只怕再也不能看见你——余华《第七天》4可是我再也没遇到一个像福贵这样令我难忘的人了,对自己的经历如此清楚,

    语文
  • 心情低落的图片压抑,心情低落的图片发朋友圈

    心情压抑的图片(心太累没人理解的说说带图片)1、有时候很想找个人倾诉一下,却又不知从何说起,最终是什么也不说,只想快点睡过去,告诉自己,明天就好了。有时候,突然会觉得

    语文
  • 经典古训100句图片大全,古训名言警句

    古代经典励志名言100句译:好的药物味苦但对治病有利;忠言劝诫的话听起来不顺耳却对人的行为有利。3良言一句三冬暖,恶语伤人六月寒。喷泉的高度不会超过它的源头;一个人的事

    语文
  • 关于青春奋斗的名人名言鲁迅,关于青年奋斗的名言鲁迅

    鲁迅名言名句大全励志1、世上本没有路,走的人多了自然便成了路。下面是我整理的鲁迅先生的名言名句大全,希望对你有所帮助!当生存时,还是将遭践踏,将遭删刈,直至于死亡而

    语文
  • 三国群英单机版手游礼包码,三国群英手机单机版攻略

    三国群英传7五神兽洞有什么用那是多一个武将技能。青龙飞升召唤出东方的守护兽,神兽之一的青龙。玄武怒流召唤出北方的守护兽,神兽之一的玄武。白虎傲啸召唤出西方的守护兽,

    语文
  • 不收费的情感挽回专家电话,情感挽回免费咨询

    免费的情感挽回机构(揭秘情感挽回机构骗局)1、牛牛(化名)向上海市公安局金山分局报案,称自己为了挽回与女友的感情,被一家名为“实花教育咨询”的情感咨询机构诈骗4万余元。

    语文