Programming > CODING SOLUTION > ITEC 1620 Introduction to Object Oriented Programming _ York University. ITEC 1620 Object-Based Prog (All)

ITEC 1620 Introduction to Object Oriented Programming _ York University. ITEC 1620 Object-Based Programming - Dec 11, 2022 Final Exam. 35 Q&A

Document Content and Description Below

York University ITEC 1620 F Object-Based Programming Dec 11, 2022 Final Exam Duration: 180 Minutes Part 1 [30] Multiple Choice Questions For each of the following questions, there is onl... y one correct answer. Please circle it. 1. Which programming language is “write once, run anywhere” A. Java B. C++ C. Python D. Ruby Answer: A 2. Which one is a source code file of Java A. Main.class B. Main.javac C. Main.java D. Main.obj Answer: C 3. Choose the right value for x and y. int n = 5; double x = 1.2 + 24.0 / n; double y = 1.2 + 24 / 5; A. 6.0, 5.2 B. 6, 5 C. 6.0, 6.0 D. 5.2, 6.0 Answer: A 4. What is the value of “res”? double x = 3.1415926; double y = 3.1415926; int res = x == y ? 1 : 0; A. 1 B. 0 C. 3.1415926 D. 4.1415926 Answer: B 5. What is the value s1+s2 where String s1 = “12” String s2 = “13” A. 1213 B. 25 C. 13 D. “1213” Answer: D 6. What is the result of output? char a = ‘A’; char b = ‘B’; System.out.println(a-b+ ‘c’) A. “1c” B. ‘d’ C. ‘b’ D. 98 Answer: D 7. Which one is not a Java keyword? MDAS 6 O O A. private B. finally C. while D. and Answer: D 8. Which Java expression is correct? A. Byte b = 256; B. float a = 1.0; C. double d = 0.999f; D. char c = -12; Answer: C 9. Which one is correct to initialize an array? A. String[] a={'a','b','c'}; B. int twoDim[][] = new int[][4]; C. int[] a={'a','b','c'} D. int[][] a = {1,2,3}; Answer: C 10. What is the result of 5/0.0? A. Infinity B. Error C. Exception D. NaN Answer: A 11. What is the result of the output? int[] ns = {1,2,3,4,5}; int sum = 0; for(int j=1; j <=5; j++){ sum += ns[j]; } System.out.println(sum) A. 14 B. 15 C. StackOverflowException D. ArrayIndexOutOfBoundsException Answer: D 12. What is the result of the output? int[][] ns = { O O O O mo O { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }; System.out.println(ns.length); A. 3 B. 4 C. 12 D. 78 Answer: A 13. What is the result of sum? int sum = 0; for(int j=1; j <=5; j++){ sum += ns[j]; } System.out.println(sum) A. 14 B. 15 C. StackOverflowException D. ArrayIndexOutOfBoundsException Answer: D 14. What is the result of the output? int sum = 0; for(int i=1; i<=200; i++){ sum += i; if(i==100) continue; } System.out.println(sum); A. 5050 B. 20100 C. 20000 it a 0 D. 19800 Answer: B 15. What is the function of method “f()”? public static int f(int[] values) { int mValue = Integer.MAX_VALUE; int index = -1; for (int i = 0; i < values.length; i++) if (values[i] < mValue) { mValue = values[i]; index = i; } return index; } A. Get the minimum value of an array B. Get the maximum value of an array C. Get the median value of an array D. Get the mean of an array Answer: A 16. The constructor in a class is called ( ) A. When a class is defined B. When an object is created C. When calling an object method D. When using an object's variable Answer: B 17. What will be the output when you compile and execute the following program. class Base { void test() { System.out.println(“Base.test()”); } } public class Child extends Base { void test() { System.out.println(“Child.test()”); } static public void main(String[] a) { Child anObj = new Child(); Base baseObj = (Base) anObj; baseObj.test(); } } A. Child.test() Base.test() B. Base.test() Child.test() C. Base.test() D. Child.test() Answer: D 18. What will be the output of the following program? public class Base { private void test() { System.out.println(6 + 6 + “ (Result)”); } static public void main(String[] a) { new Base().test(); } } A. 66(Result) B. 12(Result) C. Runtime Error.Incompatible type for +. Can’t convert an int to a string. D. Compilation Error.Incompatible type for +. Can’t add a string to an int. Answer: B 19. What is value of i, j[0], k.name after calling doSomething? public void static doSomething(int x, int[] ys, Baby b) { x = 99; ys[0] = 99; b.name = “99”; } int i = 0; int[] j = {0}; Baby k = new Baby(“50”, true); doSomething(i, j, k); A. 99, 99, 50 B. 0, 99, 50 C. 0, 0, 0 D. 0, 0, 50 ANSWER: B 20. What is the value baby.servings after running the following code___________. public class Baby{ int servings=2; void feed(int servings) { this.servings += servings; } } B aby baby = new Baby(); baby.feed(2) A. 0 B. 2 C. 4 D. 6 ANSWER: C 21~30 omitted. Part 2 [70] Short Answer Questions 31. Short answer (13 pts): (1) How many bytes of one char, int, float, double variable take up. (4 pts) (2) How many bits the integer “int a = 47;” take up in Java? (3 pts) (3) How to represent “int a = 47;” in computer (in binary)? (6 pts) Answer: (1) refer to Lecture 12. O O unitis met iii it suet net s 101 III (2) 4bytes = 4*8 = 32bits (3) 47 = 32+8+4+2+1. Thus, the binary representation of 47 is 00000000000000000000000000101111 32. Matching problem (14 pts) Here is the code of bubble sorting: match A, B, C, D to (1), (2) , (3) and (4) import java.util.Arrays; public class Main { public static void main(String[] args) { int[] ns = { 28, 12, 89, 73, 65, 18, 96, 50, 8, 36 }; System.out.println(Arrays.toString(ns)); for (int i = 0; i < ns.length - 1; i++) { for (int j = 0; j < ns.length - i - 1; j++) { if (_____(1)_____) { ______(2)_____ ______(3)____ _______(4)____ } } } System.out.println(Arrays.toString(ns)); } } A. int tmp = ns[j]; B. ns[j] = ns[j+1] C. ns[j] > ns[j+1]; D. ns[j+1]=tmp Answer: (1)àC, (2)àA, (3)àB, (4)àD 33. (13 pts) Answer the following questions Briefly: (1) You have a dataset of student’s profiles, including student ID, student name, age, gender, height, the year of enrollment. Which data structure is suitable for store these data? List, Set, or Map? Give the reason. (2) Write the pseudo code to search for all the students whose first name is ‘Smith’, return the result list. (3) Write the pseudo code to search for the student who has the highest Jaccard similarity with ‘Tom Smith’. Answer: (1) Map (HashMap) (2) linear search (3) hint: the exam question may be related to your homework. 34. Coding (15 pts): Write the function to compute all of the odd numbers in an array: public static int getOddSum(int[] values) { // your code here return sum; } 3 5. Sorting (15 pts): Given a list of integers, write the selection sorting algorithm. public static void selectionSort(int[] list) { // your code here } AD B i i i npop as itis easierto searchupthestudent yourlookingfor by looking upthepey y linear search 3 Reference: Lecture 12 1 [Show More]

Last updated: 1 year ago

Preview 1 out of 9 pages

Reviews( 0 )

$11.50

Add to cart

Instant download

Can't find what you want? Try our AI powered Search

OR

GET ASSIGNMENT HELP
61
0

Document information


Connected school, study & course


About the document


Uploaded On

Apr 18, 2023

Number of pages

9

Written in

Seller


seller-icon
PAPERS UNLIMITED™

Member since 2 years

482 Documents Sold


Additional information

This document has been written for:

Uploaded

Apr 18, 2023

Downloads

 0

Views

 61

Document Keyword Tags

More From PAPERS UNLIMITED™

View all PAPERS UNLIMITED™'s documents »

Recommended For You


$11.50
What is Browsegrades

In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Browsegrades · High quality services·