CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Similar documents
Programming with Java

CIS October 19, 2017

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

Computational Expression

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

Faculty of Science COMP-202A - Foundations of Computing (Fall 2012) - All Sections Midterm Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Final Examination

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

Faculty of Science COMP-202B - Foundations of Computing (Winter 2016) - All Sections Midterm Examination

CIS March 1, 2018

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

H212 Introduction to Software Systems Honors

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

Fundamentals of Programming Data Types & Methods

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

CIS October 16, 2018

Some Practice Midterm Problems

AP Computer Science Unit 1. Writing Programs Using BlueJ

Faculty of Science COMP-202A - Foundations of Computing (Fall 2015) - All Sections Midterm Examination

Introduction to Java Unit 1. Using BlueJ to Write Programs

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

AP Computer Science Unit 1. Writing Programs Using BlueJ

Computer Science 300 Sample Exam Today s Date 100 points (XX% of final grade) Instructor Name(s) (Family) Last Name: (Given) First Name:

Computer Science 145 Midterm 1 Fall 2016

Java Simple Data Types

CS 101 Exam 2 Spring Id Name

We now start exploring some key elements of the Java programming language and ways of performing I/O

-Alfred North Whitehead. Copyright Pearson Education, 2010 Based on slides by Marty Stepp and Stuart Reges from

Full file at

Midterm Exam 2 Thursday, November 15th, points (15% of final grade) Instructors: Jim Williams and Marc Renault

More on variables and methods

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

A variable is a name for a location in memory A variable must be declared

AP Computer Science Unit 1. Programs

Practice Midterm 1. Problem Points Score TOTAL 50

Midterms Save the Dates!

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

Java By Abstraction - Test-B (Chapters 1-6)

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Using Java Classes Fall 2018 Margaret Reid-Miller

COSC 1010 Introduction to Computer Programming

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) - All Sections Final Examination

appreciate the difference between a char and a string understand and use the String class methods

Classes and Objects Part 1

CIS November 14, 2017

CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 6, Name:

Department of Computer Science Purdue University, West Lafayette

Key Java Simple Data Types

CSE 1223: Exam II Autumn 2016

University of Palestine. Mid Exam Total Grade: 100

CIS 110 Introduction To Computer Programming. November 21st, 2011 Exam 2

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

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

AP Computer Science A

Lab5. Wooseok Kim

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Java Simple Data Types

King Saud University College of Computer and Information Sciences Computer Science Department

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 26, Name: Key

Java Classes: Random, Character A C S L E C T U R E 6

Question: Total Points: Score:

Loops and Expression Types

Topic 11 Scanner object, conditional execution

! definite loop: A loop that executes a known number of times. " The for loops we have seen so far are definite loops. ! We often use language like

COMP-202: Foundations of Programming. Lecture 5: Arrays, Reference Type, and Methods Sandeep Manjanna, Summer 2015

Controls Structure for Repetition

Question: Total Points: Score:

Prelim One Solution. CS211 Fall Name. NetID

STUDENT LESSON A10 The String Class

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

Chapter 2. Elementary Programming

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY

Place your name tag here

Building Java Programs

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

Midterm Examination (MTA)

CS 113 MIDTERM EXAM 2 SPRING 2013

A token is a sequence of characters not including any whitespace.

Final Exam. COMP Summer I June 26, points

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

COE 212 Engineering Programming. Welcome to Exam II Monday May 13, 2013

Introduction to Java (All the Basic Stuff)

COMP 202 Java in one week

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

COMP 202 Java in one week

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

BSc (Hons) Computer Science with Network Security/ BSc (Hons) Software Engineering/ BSc (Hons) Web Technologies. Examinations for 2016 Semester 1

This exam is open book. Each question is worth 3 points.

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

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

Topic 11 Scanner object, conditional execution

Transcription:

Spring 2017 Name: TUID: Page Points Score 1 28 2 18 3 12 4 12 5 15 6 15 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc. i

Some API Reminders Scanner nextint() // reads and returns next token as int nextdouble() // reads and returns next token as double next() // reads and returns next token as String nextline() // reads everything up to \n // and returns as String String class int length(); // returns the number of characters of the string int indexof(string s); // returns position of s, -1 if not there int indexof(string s, int k); //returns position of s at or past position k char charat(int k); // returns character at position k String substring(int k); //substring starting at k up to end String substring(int k, int h); //substring starting at k ending at h excluded int compareto(string anotherstring); String touppercase( ); boolean equals(string s); boolean equalsignorecase(string s); Random nextint() // returns a random integer nextint(max) // returns a random int from 0 incl to max excl nextdouble() // returns random double from 0 incl to 1.0 excl

1. (3 points) Write the line of code which declares a constant PI which is set to 3.14159. 2. (3 points) How much is a gigabyte? 3. (3 points) What is the most important job of the Java compiler? (Note: it is not to find errors in your java program.) 4. (3 points) Suppose that we have the String s. Translate the English phrase s is longer than 10 characters and begins with the letter k into a Java expression. 5. (3 points) Suppose that we have the integers x, y, z. Translate the English phrase x is odd, and is larger than the sum of y and z into a Java expression. 6. (3 points) Is OneFineDayR2 a legal Java identifier? Circle one: A. Yes B. No If not, why not? 7. What is the result of each of the following? Write ERROR if the expression contains some kind of error. (a) (2 points) 10/3 (b) (2 points) int x=10, y=20; x+10*5<y+2 x%2==0 (c) (2 points) (char)( a +1) (d) (2 points) 10%3 (e) (2 points) 4 % 5 * 6 + 297 % 10 + 4 % 8 (a) (b) (c) (d) (e) 1 of 7 question 7 continues...

(f) (2 points)!(true false) (g) (2 points) "1"+5/2+3%4*5+(6+7) (h) (2 points) 6+7*3/2+"+"+5 (f) (g) (h) 8. What s the most appropriate Java data type for each of the following? (a) (1 point) The average Philadelphia annual rainfall. (b) (1 point) The number of times that a student is absent this semester. (c) (1 point) The number of days it rained in Philadelphia last year. (d) (1 point) Your middle initial. (e) (1 point) The US national debt. (f) (1 point) Your last name. (a) (b) (c) (d) (e) 9. (6 points) What if anything is printed? Write ERROR if the code does not compile due to a compiler error. int x=55, y=66, z=77; if (x<100) if (y<80) if (z>80) System.out.println("Monday"); else System.out.println("Tuesday"); (f) out of a possible 18 2 of 7 exam continues...

10. (6 points) What if anything is printed? Write ERROR if the code does not compile due to a compiler error. int x=71; if (x>50) System.out.println("Bert"); else if (x>60) System.out.println("Ernie"); else if (x<40) System.out.println("Kermit"); else System.out.println("Elmo"); 11. (6 points) What s printed? Write ERROR if the code does not compile due to a compiler error. public class WhatsPrintedIfs { public static void main(string args[]) { int a=4; int b=11; int c=17; if (a <= b) { a = b + 1; else { a = a + 5; if (a <= c) { c++; System.out.println(a + " " + c); out of a possible 12 3 of 7 exam continues...

12. (6 points) What s printed? Write ERROR if the code does not compile due to a compiler error. public class WhatsPrinted { public static void main(string args[]) { int i, j; char c; for (i=0, j=5; i<j; i++, j--) { for (c= A ; c< D ; c++) { if (i%2==0) { System.out.println(j + " " + i + " " + c); i++; else { System.out.println(i + " " + c + " " + j); j--; 13. (6 points) What s printed? Write ERROR if the code does not compile due to a compiler error. public class WhatsPrintedLoop { public static void main(string args[]) { int i=10; do { System.out.println(i); i++; while (i<10); out of a possible 12 4 of 7 exam continues...

14. Write the few lines of code which prints the integers from 3 to 999 (inclusive) counting by 3 s (3, 6, 9, 12,... ). (a) (5 points) as a for loop (b) (5 points) as a while loop (c) (5 points) as a do-while loop out of a possible 15 5 of 7 exam continues...

15. (15 points) Write a program that asks the user to enter a series of temperatures followed by the temperature of -100 to quit. The program then prints the average of the cold temperatures, where the cutoff between cold and not cold is some constant that you ve defined in your program. (As you ve done in your homework assignments, use named constants.) If no cold temperatures are entered, print summer vacation. You may assume that you re in a region where temperatures will never be as low as -100. import java.util.scanner; public class SummerVacationSoon { public static void main(string args[]) { out of a possible 15 6 of 7 question 15 continues...

(extra space) 7 of 7 end of exam