CSE 1020 Introduction to Computer Science I A sample nal exam



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

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

AP Computer Science Java Subset

Introduction to Java

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

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

AP Computer Science File Input with Scanner

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

13 File Output and Input

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

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

Yosemite National Park, California. CSE 114 Computer Science I Inheritance

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

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

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

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

Topic 11 Scanner object, conditional execution

Building Java Programs

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

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

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

Chapter 2: Elements of Java

Building Java Programs

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

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

JAVA.UTIL.SCANNER CLASS

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

Using Files as Input/Output in Java 5.0 Applications

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

Files and input/output streams

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

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

Java (12 Weeks) Introduction to Java Programming Language

CS170 Lab 11 Abstract Data Types & Objects

Java Programming Language

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

7-1 Java Au Naturel by William C. Jones 7-1

Pemrograman Dasar. Basic Elements Of Java

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

ATM Case Study OBJECTIVES Pearson Education, Inc. All rights reserved Pearson Education, Inc. All rights reserved.

Object-Oriented Programming in Java

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

Java Programming Fundamentals

Glossary of Object Oriented Terms

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

11 November

Advanced Data Structures

Basics of Java Programming Input and the Scanner class

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

History OOP languages Year Language 1967 Simula Smalltalk

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

Introduction to Object-Oriented Programming

Supporting Data Set Joins in BIRT

Explain the relationship between a class and an object. Which is general and which is specific?

Iteration CHAPTER 6. Topic Summary

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

Fundamentals of Java Programming

Reading Input From A File

Introduction to Java. CS 3: Computer Programming in Java

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

Java Application Developer Certificate Program Competencies

Event-Driven Programming

Realizing Enterprise Integration Patterns in WebSphere

Lecture 1 Introduction to Java

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

Computer Programming I

Introduction to Java Lecture Notes. Ryan Dougherty

D06 PROGRAMMING with JAVA

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

Building Java Programs

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Crash Course in Java

JAVA ARRAY EXAMPLE PDF

1. Use the class definition above to circle and identify the parts of code from the list given in parts a j.

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

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Part 1 Foundations of object orientation

Java Interview Questions and Answers

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

CS114: Introduction to Java

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

CSE 8B Midterm Fall 2015

by Mario Fusco Monadic

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Sample CSE8A midterm Multiple Choice (circle one)

VB.NET - WEB PROGRAMMING

Chapter 2 Introduction to Java programming

Software Development with UML and Java 2 SDJ I2, Spring 2010

Introducing Variance into the Java Programming Language DRAFT

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

Programming Methods & Java Examples

Oracle Database: SQL and PL/SQL Fundamentals

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Transcription:

1 1 (8 marks) CSE 1020 Introduction to Computer Science I A sample nal exam For each of the following pairs of objects, determine whether they are related by aggregation or inheritance. Explain your answers. (a) Circle and shape. Inheritance, since a circle is-a shape. (b) Circle and radius. Aggregation, since a circle has-a radius. (c) Creditcard and date. Aggregation, since a creditcard has-an (expiry)date. (d) Creditcard and rewardcard. Inheritance, since a rewardcard is-a creditcard. 2 (8 marks) Which interface from the collections framework (Set, List or Map) would be most appropriate for representing each of the collections that are described below. Not only give your choice, but also motivate your choice. Also, include the type parameters (for example, instead of Set, give its parameterized version, like Set<String>). (a) The creditcard numbers that have been issued by a creditcard company. Set<Long>: a collection of Longs with no duplicates (each creditcard number is only used once). (b) The names of the people who are currently customers of a creditcard company. List<String>: a collection of Strings with duplicates allowed (since different people may have the same name). (c) The creditcard numbers that have been issued by a creditcard company and, for each issued creditcard number, the corresponding customer name. Map<Long, String>: mapping each number to the corresponding name.

2 (d) The names of the customers of a creditcard company and, for each customer, the creditcard numbers of the card(s) that the customer owns. List<Map<String, Set<Long>>>: each element of the list maps the name of a customer to the corresponding set of numbers (we need a list since we may have multiple customers with the same name). 3 (6 marks) Consider the following UML diagram. Shape abstract getname() : String getrandom() : Shape Circle getname() : String getradius() : int Consider the following code snippet (which appears in the body of a main method). Shape shape = Shape.getRandom(); output.print("this shape is a " + shape.getname()); if (Shape instanceof Circle) output.println(" and its radius is " + ((Circle) shape).getradius()); (a) During early binding, to which method of which class is the method call shape.getname() The method getname of the class Shape, since the declared type of shape is Shape. (b) During late binding, to which method of which class is the method call shape.getname() The method getname of the class Circle, since the actual type of shape has to be Circle (it cannot be Shape because this class is abstract). (c) During early binding, to which method of which class is the method call shape.getradius() The method getradius of the class Circle, since shape is casted to Circle.

3 4 (6 marks) Consider the following UML diagram. A x : int y : int m(a) : String m(b) : String n(a) : int B x : int y : double z : int m(a) : String n(a) : int According to the above diagram, class B extends class A. (a) How many fields are effectively present in class B? Explain your answer. Three. Both fields of A are inherited but are shadowed. (b) How many methods are effectively present in class B? Explain your answer. Three: m(a), m(b) and n(a). m(a) and n(a) of A are overwritten. inherited. 5 (6 marks) Consider the following code snippet (which appears in the body of a main method). output.print("enter a positive integer: "); int size = input.nextint(); List<Double> list = new LinkedList<Double>(); for (int i = 0; i < size; i++) list.add(math.random()); double sum = 0; for (int i = 0; i < size; i++) m(b) of A is

4 sum += list.get(i); output.println("average: " + sum / size); In this fragment, the following methods may throw runtime exceptions. method name exception type condition nextint InputMismatchException if the next token is not an integer get IndexOutOfBoundsException if the index is out of range Defensive programming and exception-based programming are two approaches to handle these runtime exceptions. For each method that may throw a runtime exception, which approach would be most appropriate? Explain your answers. For nextint, I would use an exception-based solution since it is simpler than checking if the next token to be read represents an integer. For get, defensive programming is already used: the loop only invokes the method for valid indices. 6 (4 marks) Consider the following APIs. public class Safe public Safe(Lock lock) Construct a safe with the given lock. lock a lock for the safe. public String tostring() Return a string representation of this safe. It consists of the string a safe with followed by the string representation of the lock of this safe. Returns: a string representation of this safe. public class Lock public Lock(int combination) Construct a lock with the given combination.

5 combination a combination for the lock. public void setcombination(int combination) Set the combination of this lock to the given combination. combination the new combination for this lock. public String tostring() Return a string representation of this lock. It consists of the string a lock with combination followed by the combination of this lock. Returns: a string representation of this lock. Describe how one can check if the aggregation of the classes Safe and Lock is a composition. If the snippet Lock lock = new Lock(0); Safe safe = new Safe(lock); lock.setcombination(1); output.println(safe); produces as output a safe with a lock with combination 0, then it is a composition.