CSCI 1226 Sample Midterm Exam

Similar documents
CSCI 1226 A Test #1. Wednesday, 10 October, 2018 Name: Student #: General Instructions Read and follow all directions carefully.

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

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

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Midterm Examination (MTA)

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

CSE 142, Summer 2010 Midterm Exam, Friday, July 30, 2010

Practice Midterm 1. Problem Points Score TOTAL 50

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Final Exam. COMP Summer I June 26, points

AP CS Unit 3: Control Structures Notes

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

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

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

CSCI 1226 Second Midterm Test

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

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2009

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

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

Lecture 5: Methods CS2301

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

Darrell Bethea May 25, 2011

Top-Down Program Development

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

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

STUDENT LESSON A12 Iterations

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

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

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

Programming Constructs Overview. Method Call System.out.print( hello ); Method Parameters

Programming with Java

Introduction to Computer Science Unit 2. Notes

What did we talk about last time? Examples switch statements

Loops. CSE 114, Computer Science 1 Stony Brook University

1. An operation in which an overall value is computed incrementally, often using a loop.

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

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

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

Oct Decision Structures cont d

COE 211/COE 212 Computer/Engineering Programming. Welcome to Exam II Thursday December 20, 2012

Control Structures: if and while A C S L E C T U R E 4

Java Coding 3. Over & over again!

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

CS111: PROGRAMMING LANGUAGE II

Using Java Classes Fall 2018 Margaret Reid-Miller

CSE 1223: Introduction to Computer Programming in Java Chapter 1 Computer Basics

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

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

SAMPLESAMPLESAMPLESAMPLESAMPLESAMPLESAMPLESAMPLESAMPLESAMPLE SAMPLE CSE21

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

CSE 114 Computer Science I

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

COMP 110 Project 1 Programming Project Warm-Up Exercise

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

class objects instances Fields Constructors Methods static

1 Short Answer (10 Points Each)

New York University Intro to Computer Science (CSCI-UA.101) Fall 2014 Midterm #1 Test G. Instructions:

CSCI 111 Midterm Spring 2014

CS111: PROGRAMMING LANGUAGE II

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

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

CSE 11 Midterm Fall 2008

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

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Supplementary Test 1

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Iteration statements - Loops

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

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Fundamentals of Programming Data Types & Methods

Bjarne Stroustrup. creator of C++

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

Practice Midterm 1 Answer Key

Problem Grade Total

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

Linked Lists. private int num; // payload for the node private Node next; // pointer to the next node in the list }

Introduction to Software Development (ISD) Week 3

St. Edmund Preparatory High School Brooklyn, NY

PROGRAMMING FUNDAMENTALS

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Last Class. While loops Infinite loops Loop counters Iterations

Full file at

FORM 5 COMPUTING TIME: 1h 45min

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

2.8. Decision Making: Equality and Relational Operators

Control Structures in Java if-else and switch

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Transcription:

CSCI 1226 Test #1 February 2017 General Instructions CSCI 1226 Sample Midterm Exam (A bit long since it combines parts of three earlier tests) Read and follow all directions carefully. Name: Student #: When writing programs or program segments, use the conventions used in the text for identifiers and indentation. Print clearly so that the grader can tell that the conventions are being followed. Note: not all spaces need to be filled in, but you will not need more spaces than are provided. There are 72 points available. You have 75 minutes to complete it. Good luck. 1. [12] Declare each of the following items. Use appropriate names, types, and styles. Create the most reasonable kind of item. Initialize the item if appropriate. a) the number of words entered by the user int numwords; b) the time taken by a race car for one circuit of the race track double laptime; c) whether the user is 65 or older boolean over65; d) the number of hours in a day (which is 24) public static final int HOURS_PER_DAY = 24; 2. [4] Show the output for the following program fragment. Put each character in a box by itself. int n = 42; System.out.print( The value is: ); System.out.println(n); System.out.print( The next value will be + n + 1); T h e v a l u e i s : 4 2 _ _ _ _ _ _ _ _ _ _ _ _ _ T h e n e x t v a l u e w i l l b e 4 2 1 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1 of 9

3. [2] Show the output of the following program fragment. Put each character in a box by itself. System.out.print( Open file C:\temp\newfile.txt ); O p e n f i l e C : e m p _ _ _ _ _ _ _ _ _ e w f i l e. t x t _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 4. [10] Translate the following English conditions into Java logical expressions. a) a is equal to b a == b b) b is not equal to c b!= c c) m and n are both greater than 0 m > 0 && n > 0 d) one (or both) of x and y is less than 0 x < 0 y < 0 e) resp is not No (regardless of case)!resp.equalsignorecase( No ) f) s1 starts with the letters of s2 s1.startswith(s2) 5. [4] For each of the following method calls, say whether the method is void or valuereturning. For the value-returning methods, say what the returned data type is. a) kbd.nextint() // Note: kbd is a Scanner void value-returning: int b) System.out.println() // Note: System.out is a PrintStream void value-returning: void c) response.touppercase() // Note: response is a String void value-returning: String d) Math.round(avg) // Note: avg is a double void value-returning: long or int 2 of 9

6. [6] Write a code fragment that declares and reads a word (myword) and a double (mydbl), then pauses with the message Press Enter. Assume that a Scanner named kbd has already been created. String myword; double mydbl; myword = kbd.next(); mydbl = kbd.nextdouble(); kbd.nextline(); Sopln( Press enter ); kbd.nextline(); 7. [8] Write a conditional control to assign a value to the variable toll based on the value in the variable vehicleclass, based on the following chart. vehicleclass 1 2 3 or 4 (other) toll 3.00 4.00 5.00 10.00 if (vehicleclass == 1) { toll = 3.00; else if (vehicleclass == 2) { toll = 4.00; else if (vehicleclass == 3 vehicleclass == 4) { toll = 5.00; else { toll = 10.00; 3 of 9

8. [8] Write a loop (and its associated initializations) to sum a sequence of positive integers entered by the user. The loop stops when the user enters zero or a negative number. Assume that a Scanner named kbd has already been created. sum = 0; num = kbd.nextint(); while (num > 0) { sum += num; num = kbd.nextint(); kbd.nextline(); 9. [8] Write nested for loops to produce the following output: * ** *** **** for (int line = 1; line <= 4; ++line) { for (int star = 1; star <= line; ++star) { Sop( * ); Sopln(); 4 of 9

10. [10] Write the definition of printline(int numtimes, String part). It prints a line of numtimes copies of part. For example, printline(50, = ) produces: ================================================== (The next thing printed will start just below the first = sign.) private static void printline(int numtimes, String part) { for (int time = 1; time <= numtimes; ++time) { Sop(part); Sopln(); 11. [12] Multiple Choice: select the best available answer from the options shown. A byte is made up of a) 0 or 1 bits. b) 2 bits. c) 8 bits. d) 256 bits. e) as many bits as are required to represent the object the programmer created. An example of an input device is a) a monitor. b) a mouse. c) a printer. d) the CPU. e) (all of the above) 5 of 9

An imperative computer programming language is one that a) has us draw pictures to show the computer what to do. b) has us explain to the computer what things mean. c) has us specify which operations are to be carried out at the same time. d) has us tell the computer what to do. e) is only understood by the CPU of the same kind of computer. Based on the style guidelines for this course, numstudents would be the name of a a) class. b) constant. c) method. d) variable. e) (any of the above) The command to create a Scanner named kbd is a) Scanner kbd = new Scanner(); b) Scanner kbd = new Scanner(System) c) Scanner kbd = new Scanner(System.in); d) Scanner kbd = new Scanner(System.out); e) Scanner kbd = new Scanner(System.out.print); The correct header for the main method of a program is a) public void main() b) public void static main() c) public void main(string args) d) public static void main(string[] args) e) public void static main(string[] args) The difference between main memory and secondary memory is a) main memory is inside the computer and secondary memory is outside. b) main memory is on disks and tapes, but secondary memory is just on disks. c) main memory is used for programs that are running, and secondary memory is for long-term storage. d) secondary memory is faster than main memory. e) secondary memory holds less than main memory. 6 of 9

The output of the command System.out.print( 7 / 4 = + (7 / 4)) is a) 1 = 1 b) 1.75 = 1.75 c) 7 / 4 = 1 d) 7 / 4 = 1.75 e) 7 / 4 = (7 / 4) The value of the expression 2 + 8 / 2 + 3 is a) 2 b) 2.0 c) 8 d) 9 e) 9.0 Which of the following loops does NOT iterate exactly ten times? a) for (int i = 0; i < 10; i++) { b) for (int i = 0; i <= 10; i++) { c) for (int i = 1; i <= 10; i++) { d) for (int i = 10; i > 0; i--) { e) (all of the loops above iterate exactly ten times) A method body can contain a) assignment commands. b) input commands. c) method calls. d) output commands. e) (any of the above) A value-returning method is given information by a client program, and generates an answer. The answer should be a) kept private to the class. b) kept private to the method. c) printed for the user to see and returned to the client. d) printed for the user to see. e) returned to the client. 7 of 9

Methods in the class Math (such as round, random, max, sin, cos, ) are declared a) private static b) private static final c) private void d) public static e) public void Suppose we intend to create a toroman method, which converts an integer value to its Roman numeral equivalent. For example, the Roman numeral for 42 is XLII. (Note: the method builds the Roman numeral, but it does not print the Roman numeral.) Which of the following is the best stub for this method? a) public static int toroman() {return 0; b) public static int toroman(string s) {return 0; c) public static String toroman(int n) {return XLII ; d) public static void toroman(int n) { e) public static void toroman(int n) {System.out.print( XLII ); When we try to compile the following program public class MultiChoice { public static void main(string[] args) { dothis(); private void dothis() { System.out.println("Done!"); we get the error message MultiChoice.java:3: non-static method dothis() cannot be referenced from a static context dothis(); ^ 1 error The problem is a) the method dothis should have been declared public and static. b) the method dothis should have been declared public. c) the method dothis should have been declared static. d) the method main should have been declared private. e) the method main should not have been declared static. 8 of 9

(This page is for your rough calculations. You may tear it off the exam booklet.) 9 of 9