CS 113 PRACTICE FINAL

Similar documents
1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

CS2401 QUIZ 5 February 26, questions / 20 points / 20 minutes NAME:..

CS 113 MIDTERM EXAM 2 SPRING 2013

COMP200 - Object Oriented Programming: Test One Duration - 60 minutes

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Computer Programming, I. Laboratory Manual. Final Exam Solution

CIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name:

CIS 265 Summer 2015 Exam 1 First Name Last Name

Final Examination Semester 3 / Year 2008

Questions Answer Key Questions Answer Key Questions Answer Key

CIS265 - Spring Exam 2 First Name Last Name CSU#

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Full file at Chapter 2 - Inheritance and Exception Handling

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

CS1150 Principles of Computer Science Objects and Classes

Questions Answer Key Questions Answer Key Questions Answer Key

Exam Duration: 2hrs and 30min Software Design

Introducing arrays. Week 4: arrays and strings. Creating arrays. Declaring arrays. Initialising arrays. Declaring and creating in one step

Questions Answer Key Questions Answer Key Questions Answer Key

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Chapter 1: Introduction to Computers, Programs, and Java

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Practice for Chapter 11

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015

Fundamentals of Object Oriented Programming

Inheritance Motivation

Tutorial 8 Date: 15/04/2014

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

F I N A L E X A M I N A T I O N

a) Answer all questions. b) Write your answers in the space provided. c) Show all calculations where applicable.

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

JAVA Programming Language Homework I - OO concept

COMP 250: Java Object Oriented Programming

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Lecture Notes Chapter #9_b Inheritance & Polymorphism

TeenCoder : Java Programming (ISBN )

More on Exception Handling

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

Cloning Enums. Cloning and Enums BIU OOP

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

CS 116 Week 8 Page 1

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Inheritance Sort in ascending order. Reusability 5 Sort Take The 4 Order 12,10,5,4. Class. Use this class to define a new class

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

XC Total Max Score Grader

CS 112 Programming 2. Lecture 06. Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

ITI Introduction to Computing II

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. Inheritance Hierarchy. The Idea Behind Inheritance

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario

Course Content. Objectives of Lecture 24 Inheritance. Outline of Lecture 24. CMPUT 102: Inheritance Dr. Osmar R. Zaïane. University of Alberta 4

New York University Introduction to Computer Science Midterm2 Sample Problems 2013 Andrew I. Case. Instructions:

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CMSC 331 Second Midterm Exam

CS101 Part 2: Practice Questions Algorithms on Arrays, Classes and Objects, String Class, Stack Class

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

ITI Introduction to Computing II

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer

CH. 2 OBJECT-ORIENTED PROGRAMMING

More on Exception Handling

CS 101 Exam 2 Spring Id Name

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

SAMPLE EXAM Second Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 11 November 2010

Enumerated Types. CSE 114, Computer Science 1 Stony Brook University

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Java Object Oriented Design. CSC207 Fall 2014

CMSC 132: Object-Oriented Programming II. Inheritance

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

COMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code

Arrays Classes & Methods, Inheritance

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

Two hours QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

Abstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College

Full file at

Inheritance and Polymorphism. CSE 114, Computer Science 1 Stony Brook University

Language Features. 1. The primitive types int, double, and boolean are part of the AP

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Inheritance and Polymorphism

COP 3330 Final Exam Review

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Object Oriented Programming 2015/16. Final Exam June 17, 2016

Making New instances of Classes

CS170 Introduction to Computer Science Midterm 2

I. True/False: (2 points each)

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2013

CS-202 Introduction to Object Oriented Programming

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Transcription:

CS 113 PRACTICE FINAL There are 13 questions on this test. The value of each question is: 1-10 multiple choice (4 pt) 11-13 coding problems (20 pt) You may get partial credit for questions 11-13. If you finish early, use the extra time to double check your work. You may use the summary of Java language elements that is provided. You may not use notes, books or electronic devices of any sort. All cell phones and other mobile devices must be turned off during the exam. Good luck! Name Student ID Section Answers for Questions 1 to 10 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 EXAM SCORES Q1-Q10 Q11 Q12 Q13 TOTAL

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What is the output of the following code: public class Test public static void main(string[] args) String s1 = new String("Java"); String s2 = new String("Java"); System.out.print((s1 == s2) + " " + (s1.equals(s2))); A) false false B) true true C) false true D) true false E) None of the above 2) Given the following program: public class Test public static void main(string[] args) for (int i = 0; i < args.length; i++) System.out.print(args[i] + " "); What is the output, if you run the program using java Test 1 2 3 A) 3 B) 1 2 3 C) 1 2 D) 1 E) None of the above 3) Which of the following statements represents the number of columns in a regular two-dimensional array named values? A) values[0].length B) values.length C) values.length() D) E) values[0].length() values.getcolumnlength()

4) Analyze the following code: public class Test public static void main(string[] args) A a = new A( 3 ); System.out.println(a.s); public class A private String s; public A(String s) this.s = s; public void print() System.out.println(s); A) The program has a compile error because System.out.println method cannot be invoked from a method. B) The program will display 3. C) The program has a compile error because s has not been initialized. D) The program has a compile error because you cannot create an object from the class that defines the object. E) The program has a compile error because s cannot be accessed directly outside class A. 5) What is the output of the following code? int[] mylist = 1, 5, 5, 5, 5, 1; int max = mylist[0]; int indexofmax = 0; for (int i = 1; i < mylist.length; i++) if (mylist[i] > max) max = mylist[i]; indexofmax = i; System.out.println(indexOfMax); A) 0 B) 1 C) 2 D) E) 3 4

6) Given the classes below, show the output of the following program execution: public class SmallNumberException extends Exception //------------------------------------------------------------ //Sets up exception object with a particular message. //------------------------------------------------------------ SmallNumberException (String message) super (message); Answer: public class test static public void main (String[] args) final int MIN=0; String[] values= 7, 3, this, 5 ; SmallNumberException problem=new SmallNumberException("Too small."); for (int i=0;i<values.length;i++) try if (Integer.parseInt(values[i])<MIN) throw problem; System.out.print(Integer.parseInt(values[i])%2+ ); catch (SmallNumberException e) System.out.println(e.getMessage()); catch (NumberFormatException e) System.out.println("not a number"); 7) Analyze the following code: public class Test public static void main(string[] args) int[] x = new int[5]; int i; for (i = 0; i < x.length; i++) x[i] = i; System.out.println(x[i]); A) The program displays 0 1 2 3 4. B) The program displays 4. C) The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException. D) The program has a compile error because i is not defined in the last statement in the main method. E) None of the above

8) What is the output of the following code? class Test public static void main(string[] args) try System.out.println("Welcome to Java"); int i = 0; int y = 2/i; System.out.println("Welcome to Java"); catch (ArithmeticException e) System.out.println("Exception handled"); System.out.println("End of the block"); A) The program displays Welcome to Java three times followed by End of the block. B) The program displays Welcome to Java two times followed by Exception handled. C) The program displays Welcome to Java two times followed by End of the block. D) The program displays Welcome to Java and End of the block. E) None of the above 9) Show the output of the following code: public class Test public static void main(string[] args) int[] x = 1, 2, 3, 4, 5; increase(x); int[] y = 1, 2, 3, 4, 5; increase(y[0]); System.out.println(x[0] + " " + y[0]); A) 0 0 B) 1 1 C) 2 2 D) 2 1 E) 1 2 public static void increase(int[] x) for (int i = 0; i < x.length; i++) x[i]++; public static void increase(int y) y++;

10) Consider the following class definitions: public class Employee /*....*/ public class SalariedEmployee extends Employee /*....*/ Which of the following is incorrect? A) SalariedEmployee is a subclass of Employee B) Employee is a superclass of SalariedEmployee C) SalariedEmployee inherits all properties and methods of Employee D) Employee is a subclass of java.lang.object E) Employee does not inherit from Object (example: equals())

Write your answer in the space provided. 11) Write the definition for a child class of Circle named Cylinder. The cylinder should have a double attribute named height. The constructor of the child class should take parameters to initialize the attributes. The class Cylinder should also include getter and setter method as well as an equals method that returns true if two cylinder objects have same dimensions and false otherwise. Remember to override method where needed. public class Circle protected double radius; public Circle(double r) radius=r; public void setradius(double r) radius = r; public double getradius() return radius; public double area() return Math.PI * radius * radius; public String tostring() return "Circle:Radius= " + radius;

12) Implement a method called estatistics that takes an array of strings called names. The method returns an array that contains the frequencies of letter e in every string in the original array. For example, if names= Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday the method returns the array 0, 1, 2, 0, 0, 0, 0

13) Implement a recursive method named power that takes 2 integer parameters named base and expo. The method will return the base raised to the power of expo.