CS 1331 Exam 1 Practice

Similar documents
Java Program Coding Standards Programming for Information Technology

Sample CSE8A midterm Multiple Choice (circle one)

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

Moving from CS 61A Scheme to CS 61B Java

Introduction to Java

AP Computer Science Java Subset

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

Install Java Development Kit (JDK) 1.8

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

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

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

CS 106 Introduction to Computer Science I

Introduction to Object-Oriented Programming

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

CS170 Lab 11 Abstract Data Types & Objects

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

Java Interview Questions and Answers

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Example of a Java program

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

Section 6 Spring 2013

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

Object Oriented Software Design

Iteration CHAPTER 6. Topic Summary

Chapter 2 Introduction to Java programming

Java CPD (I) Frans Coenen Department of Computer Science

Object Oriented Software Design

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

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

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

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

C++ INTERVIEW QUESTIONS

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

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

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

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

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Introduction to Programming System Design. CSCI 455x (4 Units)

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

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

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

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

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

Computer Programming I

Basics of Java Programming Input and the Scanner class

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Programming Languages CIS 443

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from

Java Basics: Data Types, Variables, and Loops

Mail User Agent Project

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Using ilove SharePoint Web Services Workflow Action

Lecture 5: Java Fundamentals III

Creating a Simple, Multithreaded Chat System with Java

Building Java Programs

Java Classes. GEEN163 Introduction to Computer Programming

CMSC 202H. ArrayList, Multidimensional Arrays

dictionary find definition word definition book index find relevant pages term list of page numbers

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

Java Crash Course Part I

Crash Course in Java

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

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

CSE 308. Coding Conventions. Reference

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

PL / SQL Basics. Chapter 3

Building Java Programs

Week 2 Practical Objects and Turtles

Installing Java (Windows) and Writing your First Program

Assignment 3 Version 2.0 Reactive NoSQL Due April 13

15-214: Principles of Software Construction 8 th March 2012

Chapter 13 - Inheritance

Building a Multi-Threaded Web Server

C Compiler Targeting the Java Virtual Machine

The C Programming Language course syllabus associate level

Java Programming Fundamentals

Chapter 2 Elementary Programming

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

Introduction to Java. CS 3: Computer Programming in Java

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

Beyond the Mouse A Short Course on Programming

Continuous Integration Part 2

Arrays in Java. Working with Arrays

Building Java Programs

Chapter 1 Java Program Design and Development

B.Sc (Honours) - Software Development

Programming and Data Structures with Java and JUnit. Rick Mercer

1001ICT Introduction To Programming Lecture Notes

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

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

LAB4 Making Classes and Objects

Visual Basic Programming. An Introduction

cs2010: algorithms and data structures

Graduate Assessment Test (Sample)

Object-Oriented Programming in Java

COSC 111: Computer Programming I. Dr. Bowen Hui University of Bri>sh Columbia Okanagan

In this Chapter you ll learn:

Transcription:

CS 1331 Exam 1 Practice Name (print clearly): Signature: GT account username (gtg, gth, msmith3, etc): Signing signifies you are aware of and in accordance with the Academic Honor Code of Georgia Tech. Calculators and cell phones are NOT allowed. This is an object-oriented programming test. Java is the required language. Java is case-sensitive. DO NOT WRITE IN ALL CAPS. A Java program in all caps will not compile. Good variable names and style are required. Comments are not required. Question Points per Page Points Lost Points Earned Graded By Page 1 9 - = Page 2 10 - = Page 3 10 - = Page 4 10 - = Page 5 20 - = Page 6 10 - = TOTAL 69 - =

1. True or False In each of the blanks below, write T if the statement beside the blank is true, F otherwise. [1] (a) A public top-level Java class may be defined in a source file with any base name as long as the file extension is.java. [1] (b) Java identifiers can contain letters, digits, and the underscore symbol and may start with a digit. [1] (c) The statement int x = 3f/4f; will compile, but the result will be truncated so that x gets the value 0. [1] (d) In a for loop header, for (initializer; condition; update), the Java compiler requires initializer to initialize a loop variable and update to update it. [1] (e) The declarations double scores[] and double[] scores are equivalent. [1] (f) Java arrays have a variable number of elements of mixed types. [1] (g) Given an array named scores, the statement scores[scores.length + 1] will not compile. [1] (h) Instance methods of a class can be called without first instaniating an object of the class. [1] (i) Every Java class has a default no-arg constructor in addition to the constructors you write yourself. Page 1 of 6 Points available: 9 - points lost: = points earned:. Graded by:

2. Expression Evaluation For each expression below, write the value and then the Java data type of the evaluated legal expression in the space provided. Be exact. The type you give must be the exact spelling of a Java primitive type including uppercase vs lowercase as it would appear in your program. Expression: 7 / 2 [1] (a) Calculated value: [1] (b) Java primitive type: Expression: 64-16 * 2 [1] (c) Calculated value: [1] (d) Java primitive type: Expression: 2.5f + 3.0-1.5f [1] (e) Calculated value: [1] (f) Java primitive type: Expression: new Double(1) / 2 [1] (g) Calculated value: [1] (h) Java primitive type: Expression: true && "Foo".equals("foo") [1] (i) Calculated value: [1] (j) Java primitive type: Page 2 of 6 Points available: 10 - points lost: = points earned:. Graded by:

3. Multiple Choice Circle the letter of the correct choice. Given: public class Kitten { private String name = ""; public Kitten(String name) { name = name; public String tostring() { return "Kitten: " + name; public boolean equals(object other) { if (this == other) return true; if (null == other) return false; if (!(other instanceof Kitten)) return false; Kitten that = (Kitten) other; return this.name.equals(that.name); Assume the following statements have been executed: Kitten maggie = new Kitten("Maggie"); Kitten fiona = new Kitten("Fiona"); Kitten fiona2 = new Kitten("Fiona"); Kitten mittens = fiona; [2] (a) What is the value of maggie? A. the address of a Kitten object B. null C. automatically set to 0 D. undefined [2] (b) What is printed on the console after the following statement is executed? System.out.println(maggie.toString()); A. Kitten: B. Kitten: null C. Kitten: Maggie [2] (c) What is the value of the expression fiona == mittens)? A. true B. false [2] (d) What is the value of the expression fiona.equals(fiona2) && fiona == mittens? A. true B. false [2] (e) After executing Kitten[] kittens = new Kitten[5];, what is the value of kittens[0]? A. null B. the address of a Kitten object C. automatically set to 0 D. undefined Page 3 of 6 Points available: 10 - points lost: = points earned:. Graded by:

4. Tracing Consider the following code: public class StrangeLogic { private static int counter = 0; private static boolean incrementcounter() { counter++; return true; public static void main(string args[]) { boolean a = true, b = false; if (b incrementcounter()) { System.out.print("Boo"); if ((a b) && incrementcounter()) { System.out.print(" ya!"); System.out.println(counter); [5] (a) What is printed when main is executed? Consider the following code: public class AlGore { public static void main(string[] args) { String mystery = "mnerigpaba"; String solved = ""; int len = mystery.length(); for (int i = 0, j = len - 1; i < len/2; ++i, --j) { solved += mystery.charat(i) + mystery.charat(j); System.out.println(solved); [5] (b) What is printed when main is executed? Page 4 of 6 Points available: 10 - points lost: = points earned:. Graded by:

5. Short Answer [2] (a) Assume you have a Java class named Foo that you want to be able to run from the command line. Write the header for the method you need to define in Foo to make it executable from the command line. [2] (b) Assume you are at the command line in the directory of the file that contains the definition for a Java class named Foo. Write the command that you would execute on the command line to compile Foo. [2] (c) If the command above executes successfully, what file will be produced? [2] (d) Write the command that will execute the Foo class you compiled above. [3] (e) What will the following code print? for (int i = 10; i > 0; i--); System.out.print( Meow! ); [4] (f) Assume you have the following start of a Student class and Student constructor. Finish the constructor. Do not change the code that is given. public class Student { private String name; private String email; public Student(String name, String email) { // Your code goes here [5] (g) Convert the following for loop to an equivalent while loop. for (int i = 10; i > 0; i--) { System.out.println(i); Page 5 of 6 Points available: 20 - points lost: = points earned:. Graded by:

6. Complete the Method [5] (a) Fill in the code for the following method that takes an array of numbers and returns the number of even numbers in the array argument. Your code should use a for loop. public int evens(int[] numbers) { // Your code goes here [5] (b) Fill in the code for the following method that takes an array of numbers and a number and returns true if the array contains the number, false otherwise. You will need a loop, and your loop must not execute more iterations than necessary, and you cannot use break or continue. public boolean contains(int[] numbers, int n) { // Your code goes here Page 6 of 6 Points available: 10 - points lost: = points earned:. Graded by: