CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Similar documents
CS 1331 Exam 1 ANSWER KEY

CS 1331 Fall 2016 Exam 2

CS 1331 Fall 2016 Exam 3 Part 1 ANSWER KEY

CS 1331 Exam 3 Practice

Exam Percentage: / 55 = %

CS 1331 Exam 3 Practice ANSWER KEY

Distributed Systems Recitation 1. Tamim Jabban

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

CS 1322 Test 2 - Version 1 Tuesday June 24 th

ANSWER KEY. Study Guide. Completely fill in the box corresponding to your answer choice for each question.

CS 101 Spring 2007 Midterm 2 Name: ID:

Distributed Systems Recitation 1. Tamim Jabban

CS 2316 Exam 3. Practice. Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Question: Total Points: Score:

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

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

CS162 Computer Science I Fall 2018 Practice Exam 1 DRAFT (9 Oct.)

Introduction to Programming Using Java (98-388)

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

CS 1316 Exam 1 Summer 2009

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

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

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)

CIT Special final examination

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

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

BM214E Object Oriented Programming Lecture 6. Classes and Objects

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Question: Total Points: Score:

Selected Questions from by Nageshwara Rao

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

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

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Recitation 3 Class and Objects

CMSC131. Creating a Datatype Class Continued Exploration of Memory Model. Reminders

COMP 401 Spring 2013 Midterm 1

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

( &% class MyClass { }

JAVA Programming Language Homework I - OO concept

Lecture 2: Java & Javadoc

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

Following is the general form of a typical decision making structure found in most of the programming languages:

public class Q extends P { private int num; private int i; P(int n) { public Q() { this.num = n;

Lecture 10. Overriding & Casting About

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

University of Massachusetts Amherst, Electrical and Computer Engineering

Prelim 1. CS 2110, March 15, 2016, 5:30 PM Total Question Name True False. Short Answer

Lecture 02, Fall 2018 Friday September 7

Place your name tag here

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

Computer Science II (20082) Week 1: Review and Inheritance

CS 113 PRACTICE FINAL

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

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

Full file at

Introduction to Java

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

CS 302 Week 9. Jim Williams

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

AP CS Unit 7: Arrays Exercises

Prelim 1. CS 2110, March 15, 2016, 7:30 PM Total Question Name True False. Short Answer

1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean

CSE 131 Introduction to Computer Science Fall Exam II

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

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

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Decision Making in C

Objects as a programming concept

Objects and Classes Lecture 2

Making New instances of Classes

3.1 Class Declaration

CS 113 MIDTERM EXAM 2 SPRING 2013

CMSC 331 Second Midterm Exam

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007

Final Exam CS 152, Computer Programming Fundamentals December 5, 2014

CS 1301 Exam 1 Fall 2014

Problem Grade Total

Abstract Classes and Interfaces

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

Operations. I Forgot 9/4/2016 COMPUTER SCIENCE DEPARTMENT PICNIC. If you forgot your IClicker, or your batteries fail during the exam

Declarations and Access Control SCJP tips

CMP 326 Midterm Fall 2015

CIS 110 Introduction to Computer Programming. 17 December 2012 Final Exam

Announcements. Final exam. Course evaluations. Saturday Dec 15 10:20 am -- 12:20 pm Room: TBA

Tutorial 12. Exercise 1: Exercise 2: CSC111 Computer Programming I

CIS 110 Introduction to Computer Programming. 13 February 2013 Make-Up Midterm Midterm

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Inheritance (Part 5) Odds and ends

Informatik II (D-ITET) Tutorial 6

CS 2316 Exam 1 Practice ANSWER KEY

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

Chapter 4 Defining Classes I

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

Java Magistère BFA

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

Transcription:

CS 1331 Exam 1 Fall 2016 Name (print clearly): GT account (gpburdell1, msmith3, etc): Section (e.g., B1): Signature: Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score. Signing signifies you are aware of and in accordance with the Academic Honor Code of Georgia Tech and that you will not discuss this exam with other students. 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 24 - = Page 2 10 - = Page 3 6 - = Page 4 4 - = Page 5 10 - = Page 6 10 - = Page 7 20 - = Page 8 0 - = TOTAL 84 - =

[16] 1. Evaluate each of the expressions below. Write down the value that they evaluate to, and the resulting data type of that value in the provided columns. If the expression is not valid Java syntax, or will throw an exception, simply write Error. Table 1: Expressions Expression Resulting Value of Expression Resulting Data Type (int)6.9 / 3 (6 % 4 == 14 % 4) "cat"+ dog foo.equals(true? bar : foo ) "I have + 5 + dogs "Pickle".substring(3,5) "Pickle".charAt(5) "cat".indexof("a") 2. Legal or Not Legal If the following lines of code would not generate any errors when compiled, write LEGAL and the resulting values of all listed variables. If it will generate a compilation error, write NOT LEGAL and explain the problem. Assume all variables are local variables. [2] (a) int i = 3; double d; d = 7 * d * 3; [2] (b) float f; double d; d = 16.0; f = (float) d / 2; [2] (c) final int num = 99; double num2 = 99.3; num2 = num++; [2] (d) long g = 12; boolean b; b = 12 - g; Page 1 of 8 Points available: 24 - points lost: = points earned:. Graded by:

3. Short Answer [2] (a) Write the header for the method you need to define in a class 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 Avengers. Write the command to compile Avengers. [2] (c) If the command above executes successfully, what file will be produced? [2] (d) Write the command that will execute the Avengers class you compiled above. [2] (e) What will the following code print? for (int i = 2; i > 0; i--) System.out.print("Go "); System.out.print("Jackets!"); Page 2 of 8 Points available: 10 - points lost: = points earned:. Graded by:

4. Multiple Choice Circle the letter of the correct choice. Given: public class Car { public String model = ""; public int year = 0; public Car(String amodel, int ayear) { model = amodel; year = ayear; public String tostring() { return "Model: " + model; public boolean equals(object other) { if (this == other) return true; if!(other instanceof Car) return false; if (this.model == ((Car) other).model) return true; return false; Assume the following statements have been executed: Car[] cars = { new Car("Camaro", 1967), new Car("Beetle", 1969), new Car("Jaguar", 2015) ; Car c = cars[1]; c.model = "VW Beetle"; [2] (a) What is the value of c? A. null B. automatically set to 0 C. cars[] D. the address of a Car object E. None of the above [2] (b) What is the value of cars.length? A. null B. the address of a Car object C. 2 D. 3 E. None of the above [2] (c) What is the value of the expression cars[1].equals(cars[2]))? A. true B. false C. This expression would cause an error to occur. Page 3 of 8 Points available: 6 - points lost: = points earned:. Graded by:

[2] (d) What is printed on the console by System.out.println(cars[1].toString());? A. Model: Beetle Year: 1969 B. Model: VW Beetle Year: 1969 C. Model: Camaro Year: 1967 D. Car: null E. None of the above [2] (e) What is printed on the console by System.out.println(cars);? A. null B. ["Model: ", "Model: ", "Model: "] C. ["Model: Camaro", "Model: Beetle", "Model: Jaguar"] D. Something like [LCar;@1db9742 Page 4 of 8 Points available: 4 - points lost: = points earned:. Graded by:

5. Tracing public class Tracer { public static void main(string[] args) { final String str = "fun 1331"; for (int i = 0; i < str.length(); i++) { if ((i < 5) (i > 2)) { System.out.print(str.charAt(i)); else { System.out.print(str.substring(i - 1, i)); if (i == 3) { System.out.println("Break time"); [5] (a) What is printed to the console when the program above is run? class Tester { public static void main(string[] args) { String[] sa = new String[4]; double[] da = new double[3]; da[0] = 0; da[1] = 5; for (int i = 0; i < da.length; i++) { sa[i+1] = i + " : "; System.out.println(sa[i] + da[i]); [5] (b) What is printed when the program above is run? Page 5 of 8 Points available: 10 - points lost: = points earned:. Graded by:

[10] 6. Class and ObjectTracing public class Poodle { private static int poodlecount = 0; private String name; public Poodle(String name) { this.name = name; poodlecount++; public void setname(string newname) { name = newname; public String getname() { return name; public String tostring() { return getname(); public String poodlecounter() { return "I am dog number " + poodlecount + "."; public static void poodlereport() { System.out.println("There are " + poodlecount + " poodles in this kennel."); public class PoodleTester { public static void main(string[] args) { Poodle curly = new Poodle("Curly"); System.out.println(curly.poodleCounter()); Poodle chloe = new Poodle("Chloe"); System.out.println(chloe.poodleCounter()); Poodle jenny = chloe; jenny.setname("jenny"); System.out.println(jenny.poodleCounter()); System.out.println(curly.poodleCounter()); Poodle.poodleReport(); What is printed when the PoodleTester is run? Page 6 of 8 Points available: 10 - points lost: = points earned:. Graded by:

7. Write the code. Be sure it would compile. [5] (a) Convert the following nested for loops to equivalent code that uses while loops instead instead of for loops. You do not need to rewrite the array declaration. String[][] arr = {{"Hello", "there", "world", {"cs 1331", "is the", "best"; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { System.out.print(arr[i][j]); System.out.println(); [15] (b) The morning of your CS1331 test, you decide to make yourself a healthy breakfast. You throw some food in the toaster. This isn t just any old toaster, though. It loves music, and it ll only toast if you let it sing along. You must create an object in Java to represent your toaster: * It has a specific number of slots for toast and other food items. - Add an instance variable to store this value. - This value is set when the object is instantiated, and the value cannot be changed afterwards. * It has a specific song it likes to sing, which it remembers by name. - Add an instance variable to store the song name, and write methods to get and set this value. Be sure to use proper conventions for your getters and setters! * Write constructors that allow the above two values to be set when creating the object. - One constructor should allow both values to be set using input parameters. - One constructor should set the number of slots to the default value of 1 and the song name to Let It Be. * Write a toast method which takes in the name of an item to toast. - This method should print out a string containing the song the toaster is singing and the item being toasted. - For example, if the song to sing is Saint Pablo and you re toasting bread, the string you print out could be Singing Saint Pablo while I toast your bread!. Write your complete Toaster class on the next page following the class heading. You do not need to write a tester for your Toaster class. Page 7 of 8 Points available: 20 - points lost: = points earned:. Graded by:

public class Toaster { Page 8 of 8 Points available: 0 - points lost: = points earned:. Graded by: