CSE 8B Midterm Fall 2015

Similar documents
Sample CSE8A midterm Multiple Choice (circle one)

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

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

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

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

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

Building Java Programs

Introduction to Java

CS170 Lab 11 Abstract Data Types & Objects

Object-Oriented Programming in Java

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

Introduction to Programming

Building Java Programs

Topic 11 Scanner object, conditional execution

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

Chapter 2: Elements of Java

Using Files as Input/Output in Java 5.0 Applications

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

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

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

CS 121 Intro to Programming:Java - Lecture 11 Announcements

AP Computer Science Static Methods, Strings, User Input

Comp 248 Introduction to Programming

JAVA ARRAY EXAMPLE PDF

Introduction to Java. CS 3: Computer Programming in Java

D06 PROGRAMMING with JAVA

INPUT AND OUTPUT STREAMS

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

Visit us at

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

Building Java Programs

java Features Version April 19, 2013 by Thorsten Kracht

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

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

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

Programming Languages CIS 443

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

Chapter 2 Introduction to Java programming

More on Objects and Classes

6.1. Example: A Tip Calculator 6-1

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

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

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

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

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

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

AP Computer Science Java Subset

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

JAVA - FILES AND I/O

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

CS 106 Introduction to Computer Science I

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

Chapter 3. Input and output. 3.1 The System class

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Division of Informatics, University of Edinburgh

13 File Output and Input

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Chapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved.

Install Java Development Kit (JDK) 1.8

Lab 5: Bank Account. Defining objects & classes

Lecture 1 Introduction to Java

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Chapter 1 Java Program Design and Development

Programming Fundamentals I CS 110, Central Washington University. November 2015

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

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

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

AP Computer Science Java Mr. Clausen Program 9A, 9B

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Week 1: Review of Java Programming Basics

CS 1302 Ch 19, Binary I/O

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

CSE 1020 Introduction to Computer Science I A sample nal exam

In this Chapter you ll learn:

Tutorial 0A Programming on the command line

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:

Introduction to programming

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

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

Line-based file processing

Building Java Programs

The following program is aiming to extract from a simple text file an analysis of the content such as:

Course Intro Instructor Intro Java Intro, Continued

Chapter 5. Recursion. Data Structures and Algorithms in Java

Running Hadoop on Windows CCNP Server

Chapter 2 Basics of Scanning and Conventional Programming in Java

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

Lecture 5: Java Fundamentals III

Homework/Program #5 Solutions

5 HDFS - Hadoop Distributed System

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Conditionals (with solutions)

Event-Driven Programming

Java 進 階 程 式 設 計 03/14~03/21

Software Development in Java

Transcription:

Name Signature Tutor Student ID CSE 8B Midterm Fall 2015 Page 1 (XX points) Page 2 (XX points) Page 3 (XX points) Page 4 (XX points) Page 5 (XX points) Total (XX points)

1. What is the Big-O complexity of the following code segments? for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { if(i == j) { System.out.println( match ); for(i = 0; i < 10; i++) { for(j = 0; j < n; j++) { if(i == j) { System.out.println( match ); for(i = 0; i < n/2; i++) { for(j = 0; j < n/2; j++) { if(i == j) { System.out.println( match ); 2. Draw the order of methods on the stack up to the indicated point of program execution, method2. Note: the stack may not fill completely, also Stacks fill from the bottom to the top: public class Example { private static int size = 4; public static void main (String[] args) { Example ex1 = new Example(); ex1.method3(); ex1.method4(); public void method1() { Example ex2 = new Example(); ex2.method2(); public void method2() { // DRAW MEMORY HERE public void method3() { method1(); public void method4() { return;

3. Given the following code: import java.util.scanner; public class DogYears { final static int AGE_FACTOR = 7; Scanner scnr = new Scanner(System.in); String name = Scruffy ; int dogageyears = 0; double result = 0; System.out.print("Enter dog's age (in years): "); dogageyears = scnr.nextint(); result = dogageyears * AGE_FACTOR; System.out.println(result); In which part of memory are the contents of the following variables stored (static, stack, or heap) a) AGE_FACTOR b) scnr c) name d) dogageyears e) result 4. What is the output from the following code: public class Question4 { Chalk c1 = new Chalk( white ); Chalk c2 = new Chalk( green ); Chalk c3 = c1; c1.write( midterm ); c2.write( test ); c3.write( Q4 ); public class Chalk { private static int numpieces = 0; private String color; public Chalk(String color) { this.numpieces++; this.color = color; public static int getnumpieces() { return numpieces; public void write(string word) { System.out.println(numPieces + / + color + / + word);

5. The following Unix commands are typed into the Unix terminal in the order that they are shown. Answer the following questions below. Assume that all Unix commands in the box have been completed. Also assume that when a file is opened, the file is created, saved and closed. If you use emacs, imagine the vim command is just emacs and the same result occurs (file is created, saved, closed). vim Apple.java mkdir Dir1 cd Dir1 vim Pear.java vim Peach.java cd.. mkdir Dir2 cd Dir2 vim Orange.java What is the output if the user types ls? What single command will copy both Pear.java and Peach.java into the current directory? The user switches into Dir1 and runs a mystery command. The output of the command is: /home/linux/ieng6/cs8b/cs8bxx/dir1 What is the mystery command? vim Grape.java vim Cherry.java 6. What gets printed in the following code: public void question6() { try { System.out.println(1); statement2; //causes Exception System.out.println(3); catch(exception e) { System.out.println(4); System.out.println(5); public void question6() throws Exception { System.out.println(1); statement2; //causes Exception System.out.println(3); System.out.println(4); System.out.println(5);

7. Explain when you would use each of the following classes: a. PrintWriter b. Scanner c. FileInputStream d. FileStream e. System (e.g. System.in or System.out) f. BufferedInputStream g. BufferedStream 8. Draw the UML diagram for the following class: public class Chalk { private int numpieces = 0; public String color; public Chalk(String color) { this.numpieces++; this.color = color; public int getnumpieces() { return numpieces; private void write(string word) { System.out.println(numPieces + / + color + / + word); 9. What is the output from the following program: public class Example { private int num; private char ch; public Example() { this(1); ch = A ; System.out.println( C1 ); public Example(int num) { this.num = num; ch = B ; System.out.println( C2 ); public void print() { System.out.println(ch); System.out.println(num); Example ex1 = new Example(2); Example ex2 = new Example(); ex1.print(); ex2.print();

10. What is the output from the following code: public class Question10 { Animal a1 = new Animal( Zebra ); Animal a2 = new Animal( Monkey ); Animal a3 = a1; setage(10, a1); setage(20, a2); setage(30, a3); a1.print(); a2.print(); a3.print(); public static void setage(int age, Animal a) { a.setage(age); public class Animal { private String type; private int age; public Animal(String type) { this.type = type; this.age = 0; public void setage(int age) { this.age = age; public void print() { System.out.println(type + age);