Dashboard / My courses / LE/EECS2030 A,B,C & E - Advanced Object Oriented Programming (Fall 2020-2021) / Term Tests / Term Test 1 LE/EECS2030 A,B,C & E - Advanced Object Oriented Programming (Fall 2020-2021) Question 1 Complete Mark 2.00 out of 5.00 Flag question Question 2 Complete Mark 2.50 out of 5.00 Flag question Question 3 Complete Mark 2.00 out of 2.00 Flag question Question 4 Complete Mark 5.00 out of 5.00 Flag question Question 5 Partially correct Mark 1.50 out of 2.00 Flag question Question 6 Complete Mark 4.00 out of 5.00 Flag question Question 7 Complete Mark 1.00 out of 5.00 Flag question Question 8 Correct Mark 5.00 out of 5.00 Flag question Question 9 Complete Mark 1.40 out of 3.00 Flag question Question 10 Complete Mark 0.00 out of 5.00 Flag question Question 11 Complete Mark 2.00 out of 2.00 Flag question Question 12 Complete Mark 7.00 out of 7.00 Flag question Question 13 Incorrect Mark 0.00 out of 5.00 Flag question Question 14 Complete Mark 5.00 out of 10.00 Flag question Question 15 Complete Mark 6.00 out of 10.00 Flag question Started on Saturday, 24 October 2020, 4:55 AM State Finished Completed on Saturday, 24 October 2020, 7:10 AM Time taken 2 hours 15 mins Grade 44.40 out of 100.00 The following class that describes a doctor, is given. Fill in the memory spaces when an object of Doctor is created like below: Program Stack Doctor() registrationNo regId onCallDays 100 100 Heap (GCH) regId 205 days onCalls Comment: The following code generates a couple of compiler errors. Your job is to tell in which line the error is reported and explain what the problem is. Line 8 is error, because it cannot make a static reference to the non-static field for memoryLimit. Comment: Line 14 also has error Which object reference(s) will be active after the following code is executed? How many reachable objects will be there after the code is executed? hisName "John" object and myName "Rose" object are active. There are 2 reachable objects. Comment: Suppose we want to write a method A) What is the pre-condition of this method (if any)? Write "None" if there is no pre-condition here. B) What is the post-condition of this method? Write "None" if there is no post-condition here. A) b cannot be zero. B) return a value is double value Comment: Consider a Student class and an instance s of the class; Which of the following are true statements about toString(). (When we say "cannot call System.out.println(...)", it means there will be compiling error in calling the method.) (You will lost marks for each wrong choice) If the Student class does not define toString(), then in main() cannot call System.out.println(s.toString()), but can call System.out.println(s); If the Student class does not define toString(), in main() can still call both System.out.println(s.toString()) and System.out.println(s); ! A class needs to define toString(), if we want to print the object of this class in a meaningful way (e.g., print attribute values) ! Call System.out.println(s) and System.out.println(s.toString()) always give same output. ! If the Student class does not define toString(), then in main() cannot call System.out.println(s.toString()), and also cannot call System.out.println(s); Every class automatically has a toString() method that is inherited from Object class. Your answer is partially correct. You have correctly selected 3. The correct answers are: Call System.out.println(s) and System.out.println(s.toString()) always give same output., If the Student class does not define toString(), in main() can still call both System.out.println(s.toString()) and System.out.println(s);, Every class automatically has a toString() method that is inherited from Object class., A class needs to define toString(), if we want to print the object of this class in a meaningful way (e.g., print attribute values) linearSearch is a method that search the content of an array for a given item. If it finds it, it returns the index at which the item has been found. If it does not find it, it returns -2. Write a piece of code that calls linearSearch on array1 and array2 to search for number 5 in array1 and number 12 in array2. Then write a print statement that prints the value of count variable. What will be printed? Your code goes in ‘main’ method. Helper help = new Helper(); System.out.println(help.linearesearch(arrar1, 5)); System.out.println(help.linearesearch(arrar2, 12)); System.out.println(help.count); Comment: Output has not been shown Write a recursive function public char maxChar (String s) that returns the 'largest' char in the argument string. A char is larger than the other if it appears later in the ASCII table than the other char. Assume the string is non-empty Example: maxChar("x") returns 'x' maxChar("Hello") returns 'o' maxChar("abc123c") returns 'c' public char maxChar (String s) { // /*char last = s.charAt(); for(int i = 0 ; i < s.length(); i++){ } */ return s.charAt(s.length()); } Comment: Which of the following is an accurate statement about the this keyword in Java? A. Can be used both in constructors and methods B. Is always needed in mutators C. Is always needed in accessors D. Is always needed when doing constructor chaining E. Can be used in front of both fields and methods, e.g., this.name this.getName() F. " return this; " is a valid statement in method. G. Is an implicit parameter in both static and non-static methods. A and G A C A, D, E and F ! B A, D and E A, D, E and G Both A-E are accurate Your answer is correct. The correct answer is: A, D, E and F Consider a class ABC the following method 1) What is the signature of the above method? 2) Which of the following method(s) can also exist in class ABC without compiling error? 1)doSomeThing(int, int, int, int, List
) 2) E Comment: What is the output of the follow code? Comment: What will be printed if num1 = 10 and num2 = 0? 10 0 10 Comment: Consider the Point2 class given below. A) Complete the Junit test method testCtr() to test if the constructor set the x y correctly B) Complete the Junit test method testSetX() to test setX() with newX being 10.5 Assume the Junit test class is outside Point2 class but within the same package as Point2 class. A) @Test public void testCtr() { Point2 point = new Point2(); //boolean want = true ; //boolean actual = assertEquals(point.x, 0.0, 0.0001); assertEquals(point.y, 0.0, 0.0001); } B) @Test public void testSetX() { Point2 point = new Point2(); point.setX(10.5); assertEquals(point.x, 10.5, 0.0001); } Comment: Consider two classes Student and Student2 in package pack1, and a Caller class in package pack2. Which of the following statement(s) is true. When we say "Caller can call ... ", it means the Caller class will not generate compiling error. (You lost marks for each wrong choice). Caller can call Student s = new Student ("Lee", 32); after import pack1.*; Caller can call pack1.Student2 s = new pack1.Student2 ("Lee", 32); without import pack1.*; Caller can call Student2 s = new Student2 ("Lee", 32); without import pack1.*; " Caller can call Student s = new Student ("Lee", 32); without import pack1.*; Caller can call pack1.Student s = new pack1.Student ("Lee", 32); without import pack1.*; Caller can call Student2 s = new Student2 ("Lee", 32); after import pack1.*; " Your answer is incorrect. The correct answers are: Caller can call Student s = new Student ("Lee", 32); after import pack1.*;, Caller can call pack1.Student s = new pack1.Student ("Lee", 32); without import pack1.*; What will be printed when the following code is executed? 1- 20 2- 19 3- 80 4- 85 5- 19 6- 18 7- 90 8- 85 9- Doe 10- Doe Comment: 2 3 7 8 9 are not correct Suppose we wish to implement a class TimeOfDay that represents a time of day. Assume that this class is implemented using an integer hour and an integer minute to represent the number of hours and minutes that have elapsed since midnight (i.e. similar to a 24 hour clock). This is to say that hours with a value greater than 12 would represent pm times. For example: 4 hours, 37 mins represents 4:37am; 15 hours, 3 mins represents 3:03pm; 22 hours 45 mins represents 10:45pm, etc (a) Complete the implementation (fill the gaps) of the default (no-argument) constructor - initializing a new TimeOfDay object to have a default time that represents midnight. (b) Complete the implementation (fill the gaps) of the custom constructor that uses two input parameters to set both of the class fields. (c) A second custom constructor accepts a single integer parameter minSinceMidnight representing the minutes elapsed since midnight. Assuming constructor "chaining" is used, complete the implementation of this constructor. (d) Complete the copy constructor such that it initializes a new TimeOfDay object from another TimeOfDay object other. (a) first gap:________this.hour = 0;_______________ second gap:_________this.minute = 0 ;________________ (b) first gap:____________this.hour = hour ; ___________ second gap:__________________this.minute = minute ;________ Quiz navigation Show one page at a time Finish review 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 # eClass English (en) $ % Li Huang You are logged in as Li Huang (Log out) LE/EECS2030 Fall 2020 Get the mobile app quartus Question 16 Complete Mark 0.00 out of 10.00 Flag question Question 17 Complete Mark 0.00 out of 5.00 Flag question Question 18 Complete Mark 0.00 out of 5.00 Flag question Question 19 Complete Mark 0.00 out of 2.00 Flag question Question 20 Complete Mark 0.00 out of 2.00 Flag question Finish review (c) first gap:__________(minSinceMidnight / 60)%24;_____________ second gap:______________minSinceMidnight %60__;_________ third gap: ____________________________ (d) first gap:_____________this.hour = other.hour;__________ second gap:________________this.minute = other.minute;__________ Comment: Fill in the memory spaces as you trace the code from the beginning of the code to line 17. Due to the limitation of eClass, an almost similar memory space as below is created for you to fill in. Comment: The following code does not let a client create an object of the class (i.e. class Q12_2) . Add a few lines of code to this class to solve this problem. You should not change anything in the current code. public Q12_2(){ } Comment: One of the components of Design by Contract is the invariants. The following function returns a substring of the input string. What is invariant in this function? The "index" is invariant in this function. Comment: The input string does not change Write javaDoc comments for the code below , so that the javaDoc looks like the following: public static int linearSearch(int[ ] myarray, int item); /** *@para myarray * Comment: Fill in the gaps in the code below, so that the type of name is the user defined String as you see in the following code, and the type of surname is the String that is defined by java. (i.e. java.lang.String). Comment: ◀ Assignment 2 Jump to... Term Test 2 ▶︎ 欢迎咨询51作业君