Java Programming. Final Examination on August 22, 2015 Summer 2015

Similar documents
Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

CS 111 Classes I 1. Software Organization View to this point:

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism

Fundamentals of Java Programming

Java (12 Weeks) Introduction to Java Programming Language

Java Programming Language

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER

CS193j, Stanford Handout #10 OOP 3

Java Application Developer Certificate Program Competencies

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Java CPD (I) Frans Coenen Department of Computer Science

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Object-Oriented Programming in Java

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

Android Application Development Course Program

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Konzepte objektorientierter Programmierung

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

16.1 DataFlavor DataFlavor Methods. Variables

CSE 1020 Introduction to Computer Science I A sample nal exam

PLV Goldstein 315, Tuesdays and Thursdays, 6:00PM-7:50PM. Tuesdays and Thursdays, 4:00PM-5:30PM and 7:50PM 9:30PM at PLV G320

Inheritance, overloading and overriding

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

J a v a Quiz (Unit 3, Test 0 Practice)

Lecture J - Exceptions

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

C++ INTERVIEW QUESTIONS

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

Java EE Web Development Course Program

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Programming Languages Featherweight Java David Walker

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1

Minnesota Virtual Academy Online Syllabus for AP Computer Science A

Basic Programming and PC Skills: Basic Programming and PC Skills:

Java Interview Questions and Answers

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Classes and Objects. Agenda. Quiz 7/1/2008. The Background of the Object-Oriented Approach. Class. Object. Package and import

Java SE 8 Programming

Glossary of Object Oriented Terms

Introduction to Java. CS 3: Computer Programming in Java

History OOP languages Year Language 1967 Simula Smalltalk

To prevent our programs to inherit multiple copies of a base class we can declare this base class as a virtual base class.

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

What are exceptions? Bad things happen occasionally

3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.

Object-Oriented Databases

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

Programming and Software Development CTAG Alignments

AP Computer Science A Syllabus

Part I. Multiple Choice Questions (2 points each):

Computing Concepts with Java Essentials

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Contents. 9-1 Copyright (c) N. Afshartous

1 Hour, Closed Notes, Browser open to Java API docs is OK

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

Chapter 1 Java Program Design and Development

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Compile-time type versus run-time type. Consider the parameter to this function:

Syllabus for CS 134 Java Programming

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Using Inheritance and Polymorphism

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Web Development in Java

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Java Software Structures

Java SE 7 Programming

The C Programming Language course syllabus associate level

Description of Class Mutation Mutation Operators for Java

AP Computer Science Java Subset

Object-Oriented Programming Lecture 2: Classes and Objects

Object-Oriented Programming in Java

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553]

CS114: Introduction to Java

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

Specialized Programme on Web Application Development using Open Source Tools

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

An Introduction to Object-Oriented Programming with

Curriculum Map. Discipline: Computer Science Course: C++

Generating Unit Tests for Checking Refactoring Safety

Teach Yourself Java in 21 Minutes

Object-Oriented Programming: Polymorphism

Computer Science 1-3 (AP) Syllabus/Online Course Plan

LOOPS CHAPTER CHAPTER GOALS

I. PREREQUISITES For information regarding prerequisites for this course, please refer to the Academic Course Catalog.

CPLEX Tutorial Handout

Integration of Application Business Logic and Business Rules with DSL and AOP

Web Service Caching Using Command Cache

Specialized Programme on Web Application Development using Open Source Tools

Introduction to Object-Oriented Programming

objectives chapter Define classes that act like blueprints for new objects, made of variables and methods. Explain encapsulation and Java modifiers.

Transcription:

Java Programming Final Examination on August 22, 2015 Summer 2015 Department of Computer Science and Information Engineering National Taiwan University Problem 1 (20 points) Multiple choice questions. Each is worth 2 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) 1. 3. 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

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. Please give an example for each question. 1. What is the definition of object-oriented paradigm. 2. What is the constructor of the class? 3. What is the difference between constructors and other methods? 4. Explain the difference between method overloading and method overriding. 5. Explain the difference between final, finally, and finalize? 6. What is this and super? 7. Explain the difference between static and instance members in one class. 8. Explain the difference between throw and throws? 9. Explain the difference between abstract classes and interfaces? 10. 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 + 1500. 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). 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. ˆ Input - n: the number of random numbers ˆ Output - Approximate number for 3 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 2

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, 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 3

ˆ 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 import java. util. Scanner ; 2 3 p u b l i c c l a s s CircleMain { 4 p u b l i c s t a t i c void main ( String [ ] args ) { 5 Scanner input = new Scanner ( System. in ) ; 6 Circle c1 = new Circle ( c1, new Point ( 0, 0), 3) ; 7 Circle c2 = new Circle ( c2, new Point ( 3, 4), 2) ; 8 input. close ( ) ; 9 showcircle ( c1 ) ; 10 showcircle ( c2 ) ; 11 System. out. println ( That c1 o v e r l a p s c2 i s + c1. isoverlap ( c2 ) +. ) ; 12 } 13 14 s t a t i c void showcircle ( Circle c ) { 15 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, 16 c. getname ( ), 17 c. getcenter ( ). getx ( ), 18 c. getcenter ( ). gety ( ), 19 c. getradius ( ), 20 c. getarea ( ), 21 c. getperimeter ( ) ) ; 22 } 23 } The result looks like: 1 c1 : ( 0. 0 0, 0. 0 0 ) with r = 3. 0 0, area = 2 8. 2 7, perimeter = 1 8. 8 5 2 c2 : ( 3. 0 0, 4. 0 0 ) with r = 2. 0 0, area = 1 2. 5 7, perimeter = 1 2. 5 7 3 That c1 overlaps c2 is f a l s e. 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: 4

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 } 11 12 t r y { 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 } Problem 8 (10 points) Write a program which simulates a TV object. diagram to define the TV class as follows: We use the class ˆ First, you need to define a TV class. ˆ Then, write a unit test to simulate the usage of the TV object. Note that the test program repeats itself until the user enter -1 to terminate the program. You can refer to the following demonstration: 5

SUBMISSION 1. Pack source codes into a zip or rar file with your full name. 2. Send the zip/rar file to d00922011@ntu.edu.tw. 3. If you have any suggestion for improving this class, feel free to leave your feedback in the e-mail. Congratulations!!! To start, you don t have to be good; to be good, you have to start. Slogan of NTU Toastmasters 6