Java Programming. Final Examination on December 13, 2015 Fall 2015
|
|
- Dennis Kelly
- 6 years ago
- Views:
Transcription
1 Java Programming Final Examination on December 13, 2015 Fall 2015 Department of Computer Science and Information Engineering National Taiwan University Problem 1 (10 points) Multiple choice questions. Each is worth 1 points. 1. Which of the following reserved words in Java is used to create an instance of a class? (a) class (b) public (c) import (d) new. 2. Given 1 double x = 5, y = 2 ; What is the value of m after the following statement is executed? 1 i n t m = ( i n t ) ( x + y + x / y x * y x / (10 * y ) ) ; (a) 1 (b) 0.75 (c) 0.5 (d) 0 (e) Object-oriented programming allows you to derive new classes from existing ones. This is called (a) inheritance (b) abstraction (c) encapsulation (d) generalization. 4. Variables of a supertype can refer to a subtype object. This is called (a) inheritance (b) polymorphism (c) encapsulation (d) dynamic binding. 5. The visibility of Java modifiers increases in which of the following order: (a) private, package, protected, and public. (b) private, protected, package, and public. (c) package, private, protected, and public. (d) package, protected, private, and public. 6. Which of the following is the type of all Java exceptions? (a) RuntimeException (b) Exception (c) Error (d) Throwable. 7. Variables that are shared by every instances of a class are (a) class variables (b) public variables (c) instance variables (d) private variables. 8. Inside a static method of a class, we can use the keyword this. (T/F) 9. Similar to classes which can extend only one other class, an interface can extend only one other interface. (T/F) 1
2 10. All constant values defined in an interface are implicitly public, static, and final. (T/F) Problem 2 (20 points) Short questions. Each is worth 2 points except that Question 8 worth 6 points. Please give an example for each question. 1. Explain the difference between method overloading and method overriding. 2. Explain the difference between final, finally, and finalize? 3. What is this and super? 4. Explain the difference between static and instance members in one class. 5. Explain the difference between throw and throws? 6. Explain the difference between abstract classes and interfaces? 7. Let x be any input of some algorithm Γ(x), n = x be the input size, and f(n) be the growth rate of Γ(x). Suppose f(n) = 4n 3 100n By definition, there exists some g(n) such that f(n) O(g(n))). Note that g(n) are simple functions like n, n 2, and log n. Determine the degree of g(n) which is a tight bound for f(n). 8. Revisit the keywords we list in the very beginning of the class. Write down the keywords you don t know yet. Problem 3 (10 points) Write a program which estimates 3 by Monte Carlo simulation. It is clear that x is less than 3 if x 2 is less than 3. You may use Math.random() in the program. 2
3 ˆ Input - n: the number of random numbers ˆ Output - Approximate number for 3 Ans: 1 package javafinal ; 2 3 p u b l i c c l a s s montecarlosqrt5 { 4 p u b l i c s t a t i c void main ( String [ ] args ) { 5 i n t n = ( i n t ) 1 e6 ; 6 f o r ( i n t i = 1 ; i <= 1 0 ; i++) { 7 System. out. printf ( %7.6 f \n, ( new MonteCarloSimulator ( n ) ). getestimate ( ) ) ; 8 } 9 } 10 } c l a s s MonteCarloSimulator { 13 p r i v a t e i n t size = 0 ; 14 p r i v a t e double estimator = 0 ; MonteCarloSimulator ( i n t n ) { 17 size = n ; 18 f o r ( i n t i = 1 ; i <= n ; i++) { 19 generateonepath ( ) ; 20 } 21 } void generateonepath ( ) { 24 double x = 2 + Math. random ( ) ; 25 i f ( x * x < 5) { 26 estimator++; 27 } 28 } p u b l i c double getestimate ( ) { 31 r e t u r n 2 + estimator / size ; 32 } 33 } Problem 4 (10 points) Given a number x, and an integer n 0, write a program which produces x n by a recursive approach. For example, 3 4 = 3 (3 (3 (3))). ˆ Input - x R - n N {0} ˆ Output - x n 3
4 Ans: 1 package javafinal ; 2 3 p u b l i c c l a s s recursiveproblem { 4 p u b l i c s t a t i c void main ( String [ ] args ) { 5 System. out. println ( Product. recursivemethod ( 3, 4) ) ; 6 System. out. println ( Product. recursivemethod ( 3. 2, 4) ) ; 7 } 8 } 9 10 c l a s s Product { 11 s t a t i c i n t recursivemethod ( i n t x, i n t n ) { 12 i f ( n > 0) { 13 r e t u r n x * recursivemethod ( x, n 1) ; 14 } e l s e { 15 r e t u r n 1 ; 16 } 17 } s t a t i c double recursivemethod ( double x, i n t n ) { 20 i f ( n > 0) { 21 r e t u r n x * recursivemethod ( x, n 1) ; 22 } e l s e { 23 r e t u r n 1 ; 24 } 25 } 26 } Problem 5 (10 points) Write a program for lottery tickets ( 樂透 ). The program draws a set of 6 distinct numbers from 1 to 49. Meanwhile, the user enters 6 distinct numbers. In the end, the program shows you how many numbers you guess right. ˆ Input - 6 distinct numbers ˆ Output - The lucky numbers - The chosen numbers - The correct numbers you have For example, 4
5 Ans: 1 import java. util. Scanner ; 2 3 p u b l i c c l a s s lotterymain { 4 s t a t i c boolean [ ] reg_table = new boolean [ 4 9 ] ; 5 s t a t i c boolean [ ] guess_table = new boolean [ 4 9 ] ; 6 7 p u b l i c s t a t i c void main ( String [ ] args ) { 8 i n t [ ] bingonum ; 9 randomsecretnumbers ( ) ; 10 System. out. println ( Welcome to Java251 Lottery Game. ) ; 11 inputnumbers ( ) ; 12 shownumbers ( guess_table ) ; 13 System. out. println ( The l o t t e r y numbers are ) ; 14 shownumbers ( reg_table ) ; 15 bingonum = checknumbers ( ) ; 16 System. out. printf ( You have c o r r e c t number ( s ) : ) ; 17 shownumbers ( bingonum ) ; 18 System. out. printf ( Bye. ) ; 19 } s t a t i c void randomsecretnumbers ( ) { 22 i n t cnt = 0 ; 23 w h i l e ( cnt < 6) { 24 i n t tmp = ( i n t ) ( Math. random ( ) *10000 % 49) ; 25 i f ( reg_table [ tmp ] == f a l s e ) 26 reg_table [ tmp ] = t r u e ; 27 e l s e 28 c o n t i n u e ; 29 cnt++; 30 } 31 } s t a t i c void shownumbers ( boolean [ ] x ) { 34 f o r ( i n t i = 0 ; i < x. length ; ++i ) { 35 i f ( x [ i ] ) 36 System. out. printf ( %3d, i + 1) ; 37 } 38 System. out. println ( ) ; 39 } 40 s t a t i c void shownumbers ( i n t [ ] x ) { 5
6 41 f o r ( i n t i = 0 ; i < x. length ; ++i ) { 42 i f ( x [ i ] > 0) 43 System. out. printf ( %3d, i + 1) ; 44 } 45 System. out. println ( ) ; 46 } s t a t i c void inputnumbers ( ) { 49 Scanner in = new Scanner ( System. in ) ; 50 i n t cnt = 0 ; 51 i n t input = 0 ; 52 System. out. println ( P l e a s e e n t e r your numbers. ) ; 53 w h i l e ( cnt < 6) { 54 System. out. printf ( [%d ] :, cnt + 1) ; 55 input = in. nextint ( ) ; 56 i f ( input > 49 input < 1) { 57 System. out. println ( Out o f range. Try again. ) ; 58 c o n t i n u e ; 59 } e l s e i f ( guess_table [ input 1 ] == t r u e ) { 60 System. out. println ( You ' ve a l r e a d y chosen t h i s number. Try again. ) ; 61 c o n t i n u e ; 62 } e l s e 63 guess_table [ input 1 ] = t r u e ; 64 cnt++; 65 } 66 in. close ( ) ; 67 } s t a t i c i n t [ ] checknumbers ( ) { 70 i n t [ ] bingo = new i n t [ 6 ] ; 71 i n t cnt = 0 ; 72 f o r ( i n t i = 0 ; i < reg_table. length ; ++i ) { 73 i f ( reg_table [ i ] && guess_table [ i ] ) 74 bingo [ cnt++] = i + 1 ; 75 } 76 r e t u r n bingo ; 77 } 78 } Problem 6 (10 points) Use Point class to define a new class Circle which has the following members: Creates two Circle objects: ˆ c 1 : center = (0, 0), radius = 3 6
7 ˆ c 2 : center = (3, 4), radius = 2 Write a program which determines if the two circles share two intersecting points. You may consider the following snippet: 1 p u b l i c c l a s s CircleMain { 2 p u b l i c s t a t i c void main ( String [ ] args ) { 3 Circle c1 = new Circle ( c1, new Point ( 0, 0), 3) ; 4 Circle c2 = new Circle ( c2, new Point ( 3, 4), 2) ; 5 input. close ( ) ; 6 showcircle ( c1 ) ; 7 showcircle ( c2 ) ; 8 System. out. println ( That c1 o v e r l a p s c2 i s + c1. isoverlap ( c2 ) +. ) ; 9 } s t a t i c void showcircle ( Circle c ) { 12 System. out. printf ( %s : (%.2 f, %.2 f ) with r = %.2 f, area = %.2 f, p e r i m e t e r = %.2 f \n, 13 c. getname ( ), 14 c. getcenter ( ). getx ( ), 15 c. getcenter ( ). gety ( ), 16 c. getradius ( ), 17 c. getarea ( ), 18 c. getperimeter ( ) ) ; 19 } 20 } The result looks like: 1 c1 : ( , ) with r = , area = , perimeter = c2 : ( , ) with r = , area = , perimeter = That c1 overlaps c2 is f a l s e. Ans: 1 c l a s s Circle { 2 p r i v a t e Point center ; 3 p r i v a t e double radius ; 4 p u b l i c String name ; 5 6 Circle ( String str, Point pt, double r ) { 7 name = str ; 8 center = pt ; 9 radius = r ; 10 } p u b l i c Point getcenter ( ) { 13 r e t u r n center ; 14 } p u b l i c double getradius ( ) { 17 r e t u r n radius ; 18 } p u b l i c double getarea ( ) { 21 r e t u r n Math. PI * Math. pow ( radius, 2) ; 22 } 7
8 23 24 p u b l i c double getperimeter ( ) { 25 r e t u r n 2 * Math. PI * radius ; 26 } p u b l i c double getdistancefrin ( Circle c ) { 29 r e t u r n center. getdistancefrom ( c. center ) ; 30 } p u b l i c boolean isoverlap ( Circle c ) { 33 r e t u r n c. getradius ( ) + radius > center. getdistancefrom ( c. center ) ; 34 } 35 } Problem 7 (10 points) Extract the member method getdistancefrom in Point class and put it in an interface metric. Also define a new class Point3D for a point in the 3D world. Their relationship can be organized as follows: Note that you should implement the function getdistancefrom in both classes. Use the following snippet to check if the classes are well-defined. In the test program, create two Point3D objects: (0, 0, 0) and (1, 2, 3). Then show the distance between these points. Besides, create an Object object which is not an object of Point3D. Try to calculate the distance. Yet, an exception occurs and is thrown by the function getdistancefrom. 1 p u b l i c c l a s s Point3Dtest { 2 p u b l i c s t a t i c void main ( String [ ] args ) { 3 Point3D p1 = new Point3D ( 0, 0, 0) ; 4 Point3D p2 = new Point3D ( 1, 2, 3) ; 5 Object p3 = new Object ( ) ; 6 t r y { 7 System. out. printf ( The d i s t a n c e between p1 and p2 i s %f. \ n, p1. getdistancefrom ( p2 ) ) ; 8 } catch ( Exception e ) { 9 System. out. println ( e. getmessage ( ) ) ; 10 } t r y { 8
9 13 System. out. printf ( The d i s t a n c e between p1 and p3 i s %f. \ n, p1. getdistancefrom ( p3 ) ) ; 14 } catch ( Exception e ) { 15 System. out. println ( e. getmessage ( ) ) ; 16 } 17 } 18 } Ans: 1 2 c l a s s Point { 3 p r o t e c t e d double x, y ; 4 5 Point ( i n t x, i n t y ) { 6 t h i s. x = x ; 7 t h i s. y = y ; 8 } 9 10 double getx ( ) { 11 r e t u r n x ; 12 } double gety ( ) { 15 r e t u r n y ; 16 } double getdistancefrom ( Point p ) { 19 r e t u r n Math. sqrt ( Math. pow ( t h i s. x p. x, 2) + Math. pow ( t h i s. y p. y, 2) ) ; 20 } 21 } i n t e r f a c e metric { 24 double getdistancefrom ( Object p ) throws Exception ; 25 } c l a s s Point3D extends Point implements metric { 28 p r i v a t e double z ; Point3D ( i n t x, i n t y, i n t z ) { 31 super ( x, y ) ; 32 t h i s. z = z ; 33 } double getz ( ) { 36 r e t u r n z ; 37 } p u b l i c double getdistancefrom ( Object obj ) throws Exception { 40 i f ( obj i n s t a n c e o f Point3D ) { 41 Point3D p = ( Point3D ) obj ; 42 r e t u r n Math. sqrt ( Math. pow ( t h i s. x p. x, 2) + Math. pow ( t h i s. y p. y, 2) + Math. pow ( t h i s. z p. z, 2) ) ; 43 } e l s e { 44 throw new Exception ( This i s not a Point3D o b j e c t. ) ; 45 } 46 } 47 } Problem 8 (20 points) Revisit the producer-and-consumer problem. In pp of 9
10 Ch9, the UseData2 object has at most 1 unit in the field data. Based on this, write a program to simulate the producer-and-consumer problem whose field data is at most 2 in the UseData2 object. For example, As a hint, you may modify the UseData2 class. To terminate the program, you may think about how to use exceptions to interrupt the main thread, which changes the flag, say, isrunning, from true to false (see the program in p. 24 of Ch9). Let s make the program run for 30 seconds. Ans: 1 p u b l i c c l a s s pcproblem { 2 3 p u b l i c s t a t i c void main ( String [ ] args ) { 4 UserData3 uc = new UserData3 ( ) ; 5 new Producer ( uc ) ; 6 new Consumer ( uc ) ; 7 } 8 9 } 10 c l a s s UserData3 { 11 p r i v a t e i n t data ; 12 long runtime = System. currenttimemillis ( ) ; 13 boolean time = t r u e ; 14 s y n c h r o n i z e d void setdata ( ) { 15 i f ( data < 2) { 16 data++; 17 System. out. printf ( P : +1 ( so data = %d ) \n, data ) ; 18 checktime ( ) ; 19 notify ( ) ; 20 } 21 e l s e t r y { 22 wait ( ) ; 23 } catch ( InterruptedException e ) {} 24 } 25 s y n c h r o n i z e d void getdata ( ) { 26 i f ( data > 0) { 27 data ; 28 System. out. printf ( C: 1 ( so data = %d ) \n, data ) ; 29 checktime ( ) ; 30 notify ( ) ; 31 } 32 e l s e t r y { 33 wait ( ) ; 10
11 34 } catch ( InterruptedException e ) {} 35 } 36 void checktime ( ) { 37 i f ( System. currenttimemillis ( ) runtime > 30000) { 38 time = f a l s e ; 39 } 40 } 41 } 42 c l a s s Consumer implements Runnable { 43 UserData3 UC ; 44 Consumer ( UserData3 UC ) { 45 t h i s. UC = UC ; 46 Thread t = new Thread ( t h i s ) ; 47 t. start ( ) ; 48 } 49 p u b l i c void run ( ) { 50 w h i l e ( UC. time ) { 51 UC. getdata ( ) ; 52 t r y { 53 Thread. sleep ( ( i n t ) ( Math. random ( ) * 1000) * 2) ; 54 } catch ( InterruptedException e ) {} 55 } 56 } 57 } 58 c l a s s Producer implements Runnable { 59 UserData3 UC ; 60 Producer ( UserData3 UC ) { 61 t h i s. UC = UC ; 62 Thread t = new Thread ( t h i s ) ; 63 t. start ( ) ; 64 } 65 p u b l i c void run ( ) { 66 w h i l e ( UC. time ) { 67 UC. setdata ( ) ; 68 t r y { 69 Thread. sleep ( ( i n t ) ( Math. random ( ) * 1000) * 2) ; 70 } catch ( InterruptedException e ) {} 71 } 72 } 73 } SUBMISSION 1. Pack source codes into a zip or rar file with your full name. 2. Send the zip/rar file to d @ntu.edu.tw. 3. If you have any suggestion for improving this class, feel free to leave your feedback in the . Congratulations!!! To start, you don t have to be good; to be good, you have to start. Slogan of NTU Toastmasters 11
Techniques of Java Programming
Legi-Nr.:... Techniques of Java Programming ETH Zurich Date: 9 May 008 Family name, first name:... Student number:... I confirm with my signature, that I was able to take this exam under regular circumstances
More informationDiscovering Spam On Twitter
Virginia Commonwealth University VCU Scholars Compass Theses and Dissertations Graduate School 2014 Discovering Spam On Twitter Ioana-Alexandra Bara Virginia Commonwealth University Follow this and additional
More informationSDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version
SDS developer guide Develop distributed and parallel applications in Java Nathanaël Cottin sds@ncottin.net http://sds.ncottin.net version 0.0.3 Copyright 2007 - Nathanaël Cottin Permission is granted to
More informationCS Java. Introduction to Java. Andy Mroczkowski Department of Computer Science Drexel University
CS 190 - Java Introduction to Java Andy Mroczkowski uamroczk@cs.drexel.edu Department of Computer Science Drexel University February 18, 2008 / Lecture 5 Outline Course Status Course Information & Schedule
More informationFACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 09/06/2014 SESSION 8:30-10:30
FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING MODULE CAMPUS CSC2A10 OBJECT ORIENTED PROGRAMMING AUCKLAND PARK CAMPUS (APK) EXAM JUNE 2014 DATE 09/06/2014 SESSION 8:30-10:30 ASSESOR(S)
More informationCS-140 Fall 2018 Test 2 Version Practice Nov. 12, Name:
CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T F : If a child overrides its parent
More information1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;
1 Trees The next major set of data structures belongs to what s called Trees. They are called that, because if you try to visualize the structure, it kind of looks like a tree (root, branches, and leafs).
More informationINF Models of concurrency
INF4140 - Models of concurrency Fall 2017 October 17, 2017 Abstract This is the handout version of the slides for the lecture (i.e., it s a rendering of the content of the slides in a way that does not
More informationExtensibility Patterns: Extension Access
Design Patterns and Frameworks Dipl.-Medieninf. Christian Piechnick INF 2080 christian.piechnick@tu-dresden.de Exercise Sheet No. 5 Software Technology Group Institute for SMT Department of Computer Science
More informationVoortgezet Programmeren
Voortgezet Programmeren Lecture 4: Interfaces and polymorphism Tommi Tervonen Econometric Institute, Erasmus School of Economics Rule #1: never duplicate code p u b l i c c l a s s Course { p u b l i c
More informationCS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018
CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T X F : If a child overrides its parent
More informationMore Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018
CS 61B More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018 Here is a review of some formulas that you will find useful when doing asymptotic analysis. ˆ N i=1 i = 1 + 2 + 3 + 4 + + N = N(N+1)
More informationpublic void run ( ) { i f ( this. id == 0) System. out. p r i n t ( 3 ) ; bro. j o i n ( ) ; else System. out. p r i n t ( 2 ) ;
1 Unusual programs 1. Consider the following Java program : public c l a s s Thread2 extends Thread { public int id ; public Thread2 bro ; public Thread2 ( int id, Thread2 bro ) { this. id = id ; this.
More informationCS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:
CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides
More informationIntroduction to Programming (Java) 3/12
Introduction to Programming (Java) 3/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction
More informationWritten Homework #1: Analysis of Algorithms
Written Homework #1: Analysis of Algorithms CIS 121 Fall 2016 cis121-16fa-staff@googlegroups.com Due: Thursday, September 15th, 2015 before 10:30am (You must submit your homework online via Canvas. A paper
More informationFACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 07/2014 SESSION 8:00-10:00
FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING MODULE CAMPUS CSC2A10 OBJECT ORIENTED PROGRAMMING AUCKLAND PARK CAMPUS (APK) EXAM JULY 2014 DATE 07/2014 SESSION 8:00-10:00 ASSESOR(S)
More informationElementary Sorts 1 / 18
Elementary Sorts 1 / 18 Outline 1 Rules of the Game 2 Selection Sort 3 Insertion Sort 4 Shell Sort 5 Visualizing Sorting Algorithms 6 Comparing Sorting Algorithms 2 / 18 Rules of the Game Sorting is the
More informationCMSC 132, Object-Oriented Programming II Summer Lecture 11:
CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 11: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 11.1 Recursion
More informationIntroduction to Computer Programming, Spring Term 2018 Practice Assignment 1 Discussion:
German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Mohammed Abdel Megeed Introduction to Computer Programming, Spring Term 2018 Practice Assignment 1 Discussion:
More informationSFWR ENG/COMP SCI 2S03 Principles of Programming
(Slide 1 of 78) Dr. Ridha Khedri Department of Computing and Software, McMaster University Canada L8S 4L7, Hamilton, Ontario Acknowledgments: Material based on Java actually: A Comprehensive Primer in
More informationExercise 1 (15 points)
Exam System Validation (214012) 8:45-12:15, 25-06-2010 The exercises are worth a total of 90 points. The final grade is 10+pts 10. The exam is open book: copies of slides/papers/notes/etc. are allowed.
More informationBlocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012)
1 Streams Blocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012) Streams provide a very simple abstraction for determinate parallel computation. The intuition for streams is already present in
More informationSolutions. Prelim 2[Solutions]
Prelim [Solutions]. Short Answer [ pts] (a) [ pts] A traversal of an expression tree produces the string + + 3. i. What kind of traversal is it? Preorder; the operator is printed before the operands. ii.
More informationObject Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20
Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20 This is a closed-book exam. Any form of cheating or lying will not be tolerated. Students can get zero scores and/or fail the class and/or
More informationCS Exam 1 Study Guide and Practice Exam
CS 150 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Suggestions, Warnings, and Resources.................................
More informationCS1083 Week 4 : Polymorphism
CS1083 Week 4 : Polymorphism Interfaces, Comparable, Searching David Bremner 2018-01-22 Interfaces Linear Search Binary Search Interfaces An interface is like a class, with all the implementation left
More informationPrelim 2[Solutions] Solutions. 1. Short Answer [18 pts]
Prelim [Solutions]. Short Answer [8 pts] (a) [3 pts] In a model/view/controller, Swing is likely to be part of (there may be more than one): i. the model ii. the view iii. the controller The view and the
More informationThomas Jefferson Invitational Open in Informatics
Thomas Jefferson Invitational Open in Informatics Sample Problems (With Solutions) Version 2.01.1 By programmers, For programmers Preface Preface Welcome to the TJ IOI Sample Problems document. Here, you
More informationInstance Methods and Inheritance (1/2)
Instance Methods and Inheritance (1/2) 1 class Professor { 2 p u b l i c void say_hello ( ) { 3 System. out. p r i n t l n ( " Hello! " ) ; 4 } 5 } 6 class CSIEProfessor extends Professor { 7 p u b l i
More informationCS 163/164 - Exam 1 Study Guide and Practice Exam
CS 163/164 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Strings...................................................
More informationObject Oriented Programming for Python
Object Oriented Programming for Python Bas Roelenga Rijksuniversiteit Groningen Kapteyn Institute February 20, 2017 Bas Roelenga (RUG) February 20, 2017 1 / 21 Why use Object Oriented Programming? Code
More informationComputer Science Introductory Course MSc - Introduction to Java
Computer Science Introductory Course MSc - Introduction to Java Lecture 3:,, Pablo Oliveira ENST Outline 1 2 3 Definition An exception is an event that indicates an abnormal condition
More informationMore About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010
More About Methods Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 8-9, 2010 H.-T. Lin (NTU CSIE) More About Methods OOP 03/08-09/2010 0 / 24 Methods: the Basic Method (1/2, Callee s View) 1 p
More informationSubmit Growable Array exercise Answer Q1-3 from today's in-class quiz.
Q1-3 Growable Arrays Continued Big-Oh and its cousins Submit Growable Array exercise Answer Q1-3 from today's in-class quiz. } Finish course intro } Growable Array recap } Big-Oh and cousins } After today,
More informationMaps performance tips On server: Maintain DB connections, prepared statements (per thread/request!)
Announcements Maps performance tips On server: Maintain DB connections, prepared statements (per thread/request!) Use Spark.before, Spark.after to open and close. Use ThreadLocal, or pass the connection
More informationLecture 5: Sep. 23 &25
CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 5: Sep. 23 &25 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 5.1 Doubly Linked
More informationTou has been released!
Tou has been released! Shoot- em-up, heavy use of collision detection Much more open-ended than previous projects Easier than previous projects if you work smart Should help those of you combating the
More informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationDM507 - Algoritmer og Datastrukturer Project 1
DM507 - Algoritmer og Datastrukturer Project 1 Christian Skjøth Mat-Øk 280588 Morten Olsen Mat-Øk 090789 19. marts 2012 Task 1 - Double for-loop So, first we needed to create an instance of the class File
More informationCS 177 Fall 2014 Midterm 1 exam - October 9th
CS 177 Fall 2014 Midterm 1 exam - October 9th There are 25 True/False and multiple choice questions. Each one is worth 4 points. Answer the questions on the bubble sheet given to you. Remember to fill
More informationMath 231E, Lecture 25. Integral Test and Estimating Sums
Math 23E, Lecture 25. Integral Test and Estimating Sums Integral Test The definition of determining whether the sum n= a n converges is:. Compute the partial sums s n = a k, k= 2. Check that s n is a convergent
More informationCMSC 132, Object-Oriented Programming II Summer Lecture 10:
CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 10: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 10.1 RECURSION
More informationItem 6. Pi and the Universe. Gives Applications to the Geometry of our Universe. 5 Total Pages
Item 6 Pi and the Universe Gives Applications to the Geometry of our Universe 5 Total Pages 1 Pi and the Universe How Geometry Proves the Correct Ratio for Pi 201/64, as a decimal 3.140625 For our geometry
More informationMore on Methods and Encapsulation
More on Methods and Encapsulation Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 31, 2009 H.-T. Lin (NTU CSIE) More on Methods and Encapsulation OOP(even) 03/31/2009 0 / 38 Local Variables Local
More informationCSE 311: Foundations of Computing. Lecture 10: Set Operations & Representation, Modular Arithmetic
CSE 311: Foundations of Computing Lecture 10: Set Operations & Representation, Modular Arithmetic Definitions A and B are equal if they have the same elements A = B x (x A x B) A is a subset of B if every
More informationDesign Patterns and Refactoring
Singleton Oliver Haase HTWG Konstanz 1 / 19 Description I Classification: object based creational pattern Puropse: ensure that a class can be instantiated exactly once provide global access point to single
More informationCSE 331 Winter 2018 Homework 1
Directions: - Due Wednesday, January 10 by 11 pm. - Turn in your work online using gradescope. You should turn in a single pdf file. You can have more than one answer per page, but please try to avoid
More informationLecture 5: Jun. 10, 2015
CMSC 132, Object-Oriented Programming II Summer 2015 Lecturer: Anwar Mamat Lecture 5: Jun. 10, 2015 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor.
More informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationSFWR ENG 3S03: Software Testing
(Slide 1 of 69) Dr. Ridha Khedri Writing in Department of Computing and Software, McMaster University Canada L8S 4L7, Hamilton, Ontario Acknowledgments: Material based on [HT03] Unit Testing in Java with
More informationSection 9.2 Objective: Students will be able to define and work with irrational numbers.
Lincoln Public Schools Math 8 McDougall Littell Middle School Math Course 3 Chapter 9 Items marked A, B, C are increasing in difficulty. Group A questions are the most basic while Group C are the most
More informationClojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014
Clojure Concurrency Constructs, Part Two CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014 1 Goals Cover the material presented in Chapter 4, of our concurrency textbook In particular,
More informationThe Midterm Exam. Hsuan-Tien Lin. Department of CSIE, NTU. OOP Class, April 26-27, 2010
The Midterm Exam Hsuan-Tien Lin Department of CSIE, NTU OOP Class, April 26-27, 2010 H.-T. Lin (NTU CSIE) The Midterm Exam OOP 04/26-27/2010 0 / 20 Java Night Countdown I 1 (2%) What is the fully-qualified
More informationCS 4110 Programming Languages & Logics. Lecture 25 Records and Subtyping
CS 4110 Programming Languages & Logics Lecture 25 Records and Subtyping 31 October 2016 Announcements 2 Homework 6 returned: x = 34 of 37, σ = 3.8 Preliminary Exam II in class on Wednesday, November 16
More information(b). What is an expression for the exact value of P(X = 4)? 2. (a). Suppose that the moment generating function for X is M (t) = 2et +1 3
Math 511 Exam #2 Show All Work 1. A package of 200 seeds contains 40 that are defective and will not grow (the rest are fine). Suppose that you choose a sample of 10 seeds from the box without replacement.
More informationBasic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University
Basic Java OOP 10/12/2015 Hsuan-Tien Lin ( 林軒田 ) htlin@csie.ntu.edu.tw Department of Computer Science & Information Engineering National Taiwan University ( 國立台灣大學資訊工程系 ) Hsuan-Tien Lin (NTU CSIE) Basic
More information1 Java Night Countdown (30%)
Midterm Examination Problem Sheet TIME: 04/18/2009, 19:00 21:00 This is a open-textbook exam. You can use the Absolute Java textbook as your reference during the exam. Any other references are not allowed.
More informationProblem Decomposition: One Professor s Approach to Coding
Problem Decomposition: One Professor s Approach to Coding zombie[1] zombie[3] Fewer Buuuuugs zombie[4] zombie[2] zombie[5] zombie[0] Fundamentals of Computer Science I Overview Problem Solving Understand
More informationPoint of intersection
Name: Date: Period: Exploring Systems of Linear Equations, Part 1 Learning Goals Define a system of linear equations and a solution to a system of linear equations. Identify whether a system of linear
More informationDesign Pattern. Observer Pattern
Design Pattern Weather Data Weather Data display 2 TestDisplay package nonpattern; import javax.swing.*; public class TextDisplay extends JPanel { JLabel label; public TextDisplay() { label = new JLabel("
More informationCS 61B Asymptotic Analysis Fall 2017
CS 61B Asymptotic Analysis Fall 2017 1 More Running Time Give the worst case and best case running time in Θ( ) notation in terms of M and N. (a) Assume that slam() Θ(1) and returns a boolean. 1 public
More information1. Write a program to calculate distance traveled by light
G. H. R a i s o n i C o l l e g e O f E n g i n e e r i n g D i g d o h H i l l s, H i n g n a R o a d, N a g p u r D e p a r t m e n t O f C o m p u t e r S c i e n c e & E n g g P r a c t i c a l M a
More informationClass IX Chapter 1 Number Sustems Maths
Class IX Chapter 1 Number Sustems Maths Exercise 1.1 Question Is zero a rational number? Can you write it in the form 0? and q, where p and q are integers Yes. Zero is a rational number as it can be represented
More informationPython. chrysn
Python chrysn 2008-09-25 Introduction Structure, Language & Syntax Strengths & Weaknesses Introduction Structure, Language & Syntax Strengths & Weaknesses Python Python is an interpreted,
More informationExercise 1: Formal Tools and Techniques (10 points)
EXAM System Validation (191401) 13:45-17:15 0-07-01 The exercises are worth a total of 100 points. The final grade for the course is (hw 1+hw )/+exam/10, provided that you obtain at least 50 points for
More information13 Concurrent Programming using Tasks and Services
60 Advanced Java for Bioinformatics, WS 17/18, D. Huson, January 18, 2018 13 Concurrent Programming using Tasks and Services Any programs that you write will be multi-threaded. Modern computers have multiple
More information1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal
Präsenzstunden Today In the same room as in the first week Assignment 5 Felix Friedrich, Lars Widmer, Fabian Stutz TA lecture, Informatics II D-BAUG March 18, 2014 HIL E 15.2 15:00-18:00 Timon Gehr (arriving
More informationCSE505, Fall 2012, Final Examination December 10, 2012
CSE505, Fall 2012, Final Examination December 10, 2012 Rules: The exam is closed-book, closed-notes, except for one side of one 8.5x11in piece of paper. Please stop promptly at 12:20. You can rip apart
More informationCSE 311: Foundations of Computing. Lecture 10: Set Operations & Representation, Modular Arithmetic
CSE 311: Foundations of Computing Lecture 10: Set Operations & Representation, Modular Arithmetic Definitions A and B are equalif they have the same elements A = B x(x A x B) A is a subsetof B if every
More informationIntroduction to Computer Programming, Spring Term 2018 Practice Assignment 1 Discussion:
German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Rimon Elias Dr. Hisham Othman Introduction to Computer Programming, Spring Term 2018 Practice Assignment 1 Discussion:
More informationCheckpoint Questions Due Monday, October 1 at 2:15 PM Remaining Questions Due Friday, October 5 at 2:15 PM
CS103 Handout 03 Fall 2012 September 28, 2012 Problem Set 1 This first problem set is designed to help you gain a familiarity with set theory and basic proof techniques. By the time you're done, you should
More informationSolutions to the exam in Real-Time Systems
Solutions to the exam in Real-Time Systems 140107 These solutions are available on WWW: http://www.control.lth.se/course/frtn01/ 1. 2. a. Selecting the state variables as [y(t) ẏ(t) ÿ(t)] T gives the state
More informationGenerics. Hsuan-Tien Lin. OOP Class, May 23, Department of CSIE, NTU. H.-T. Lin (NTU CSIE) Generics OOP 05/23/ / 16
Generics Hsuan-Tien Lin Department of CSIE, NTU OOP Class, May 23, 2013 H.-T. Lin (NTU CSIE) Generics OOP 05/23/2013 0 / 16 How can we write a class for an Integer set of arbitrary size? H.-T. Lin (NTU
More informationGo Tutorial. Ian Lance Taylor. Introduction. Why? Language. Go Tutorial. Ian Lance Taylor. GCC Summit, October 27, 2010
GCC Summit, October 27, 2010 Go Go is a new experimental general purpose programming language. Main developers are: Russ Cox Robert Griesemer Rob Pike Ken Thompson It was released as free software in November
More informationReport of Dragable Notebook
Report of Dragable Notebook Lu Guandong, Qi Zhenlin, Mao Yong, Han Bing May 18, 2017 Abstract This report shows you why we develop the app, the function of the app and the features of the app. We include
More informationFIT100 Spring 01. Project 2. Astrological Toys
FIT100 Spring 01 Project 2 Astrological Toys In this project you will write a series of Windows applications that look up and display astrological signs and dates. The applications that will make up the
More informationProf. Israel Nwaguru PLANE TRIGONOMETRY - MATH 1316, CHAPTER REVIEW
Prof. Israel Nwaguru PLANE TRIGONOMETRY - MATH 1316, CHAPTER 1.1-1.4 REVIEW Multiple Choice Identify the choice that best completes the statement or answers the question. 1. Determine the quadrant in which
More informationCOMP 204. Exceptions continued. Yue Li based on material from Mathieu Blanchette, Carlos Oliver Gonzalez and Christopher Cameron
COMP 204 Exceptions continued Yue Li based on material from Mathieu Blanchette, Carlos Oliver Gonzalez and Christopher Cameron 1 / 27 Types of bugs 1. Syntax errors 2. Exceptions (runtime) 3. Logical errors
More informationCS177 Spring Final exam. Fri 05/08 7:00p - 9:00p. There are 40 multiple choice questions. Each one is worth 2.5 points.
CS177 Spring 2015 Final exam Fri 05/08 7:00p - 9:00p There are 40 multiple choice questions. Each one is worth 2.5 points. Answer the questions on the bubble sheet given to you. Only the answers on the
More informationLab Exercise 6 CS 2334
Lab Exercise 6 CS 2334 September 28, 2017 Introduction In this lab, you will experiment with using inheritance in Java through the use of abstract classes and interfaces. You will implement a set of classes
More informationIntroduction to Computing II (ITI 1121) FINAL EXAMINATION
Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification
More informationLists, Stacks, and Queues (plus Priority Queues)
Lists, Stacks, and Queues (plus Priority Queues) The structures lists, stacks, and queues are composed of similar elements with different operations. Likewise, with mathematics: (Z, +, 0) vs. (Z,, 1) List
More informationClass versus Instance (Section 5.1)
Class versus Instance (Section 5.1) Hsuan-Tien Lin Department of CSIE, NTU OOP Class, March 22-23, 2010 H.-T. Lin (NTU CSIE) Class versus Instance OOP 03/22-23/2010 0 / 16 Static Variables (1/2) 1 class
More informationGrade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2
1 Faculty of Mathematics Waterloo, Ontario Centre for Education in Mathematics and Computing Grade 11/12 Math Circles Fall 2014 - Nov. 5 Recurrences, Part 2 Running time of algorithms In computer science,
More informationÜbung Informatik I - Programmierung - Blatt 7
RHEINISCH- WESTFÄLISCHE TECHNISCHE HOCHSCHULE AACHEN LEHR- UND FORSCHUNGSGEBIET INFORMATIK II RWTH Aachen D-52056 Aachen GERMANY http://programmierung.informatik.rwth-aachen.de LuFG Informatik II Prof.
More informationMURA Office hours Thurs at 12-1pm in CIT 546 Contact for more info.
Course Announcements Lecture capture has begun, available from Lectures page. First two and a half weeks are packed. Testing lab done, HTML started, and Stars due next Friday. Department has a lot of student
More informationMATH 1314 Test 2 Review
Name: Class: Date: MATH 1314 Test 2 Review Multiple Choice Identify the choice that best completes the statement or answers the question. 1. Find ( f + g)(x). f ( x) = 2x 2 2x + 7 g ( x) = 4x 2 2x + 9
More informationbesides your solutions of these problems. 1 1 We note, however, that there will be many factors in the admission decision
The PRIMES 2015 Math Problem Set Dear PRIMES applicant! This is the PRIMES 2015 Math Problem Set. Please send us your solutions as part of your PRIMES application by December 1, 2015. For complete rules,
More informationGrade 5 Geometry. Answer the questions. Choose correct answer(s) from the given choices. Fill in the blanks
ID : cn-5-geometry [1] Grade 5 Geometry For more such worksheets visit www.edugain.com Answer the questions (1) What is the common term for the perimeter of a circle? (2) What is the perimeter of an isosceles
More informationA Java introduction SDK, FC 15/12/2009 UMR AMAP. SDK, FC (UMR AMAP) A Java introduction 15/12/ / 50
A Java introduction SDK, FC UMR AMAP 15/12/2009 SDK, FC (UMR AMAP) A Java introduction 15/12/2009 1 / 50 Plan 1 Introduction 2 Bases Java Application Variables & Expressions Simple Arrays Exceptions Collections
More informationRead all questions and answers carefully! Do not make any assumptions about the code other than those that are clearly stated.
Read all questions and answers carefully! Do not make any assumptions about the code other than those that are clearly stated. CS177 Fall 2014 Final - Page 2 of 38 December 17th, 10:30am 1. Consider we
More informationHow many hours would you estimate that you spent on this assignment?
The first page of your homework submission must be a cover sheet answering the following questions. Do not leave it until the last minute; it s fine to fill out the cover sheet before you have completely
More informationSoftware Engineering
Software Engineering Lecture 07: Design by Contract Peter Thiemann University of Freiburg, Germany 02.06.2014 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationCSE 311 Lecture 11: Modular Arithmetic. Emina Torlak and Kevin Zatloukal
CSE 311 Lecture 11: Modular Arithmetic Emina Torlak and Kevin Zatloukal 1 Topics Sets and set operations A quick wrap-up of Lecture 10. Modular arithmetic basics Arithmetic over a finite domain (a.k.a
More informationSharing Objects. Pieter van den Hombergh. Fontys Hogeschool voor Techniek en Logistiek. February 15, 2017
Pieter van den Hombergh Fontys Hogeschool voor Techniek en Logistiek February 15, 2017 and /FHTenL February 15, 2017 is safe Idioms 1/34 and and is safe Idioms /FHTenL February 15, 2017 2/34 visibility
More informationModern Functional Programming and Actors With Scala and Akka
Modern Functional Programming and Actors With Scala and Akka Aaron Kosmatin Computer Science Department San Jose State University San Jose, CA 95192 707-508-9143 akosmatin@gmail.com Abstract For many years,
More informationCSCI-141 Exam 1 Review September 19, 2015 Presented by the RIT Computer Science Community
CSCI-141 Exam 1 Review September 19, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Python basics (a) The programming language Python (circle the best answer): i. is primarily
More informationBoardGame: A MiniDraw extension
BoardGame: A MiniDraw extension Henrik Bærbak Christensen Status: Draft. November 29, 2010 Chapter 1 Boardgame Architecture The MiniDraw framework is described in Chapter 30 in Flexible, Reliable Software.
More informationITI Introduction to Computing II
(with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!
More information