关键词不能为空

当前您在: 主页 > 英语 >

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)的相关文章

  • 爱心与尊严的高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊严高中作文题库

    1.关于爱心和尊严的作文八百字 我们不必怀疑富翁的捐助,毕竟普施爱心,善莫大焉,它是一 种美;我们也不必指责苛求受捐者的冷漠的拒绝,因为人总是有尊 严的,这也是一种美。

    小学作文
  • 爱心与尊重的作文题库

    1.作文关爱与尊重议论文 如果说没有爱就没有教育的话,那么离开了尊重同样也谈不上教育。 因为每一位孩子都渴望得到他人的尊重,尤其是教师的尊重。可是在现实生活中,不时会有

    小学作文
  • 爱心责任100字作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任心的作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文
  • 爱心责任作文题库

    1.有关爱心,坚持,责任的作文题库各三个 一则150字左右 (要事例) “胜不骄,败不馁”这句话我常听外婆说起。 这句名言的意思是说胜利了抄不骄傲,失败了不气馁。我真正体会到它

    小学作文