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

Similar documents
CSCI 1226 Sample Midterm Exam

EXCEPTION HANDLING. // code that may throw an exception } catch (ExceptionType parametername) {

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

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

AP Computer Science Unit 1. Programs

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

AP CS Unit 3: Control Structures Notes

CSCI 1226 Second Midterm Test

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

AP Computer Science Unit 1. Writing Programs Using BlueJ

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

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

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

First Java Program - Output to the Screen

Supplementary Test 1

Chapter 2: Basic Elements of Java

AP Computer Science Unit 1. Writing Programs Using BlueJ

Unit 1: Binary and Java Input and Output. Sample Test (Inquiry) Name : Totals: /70 (!c), /9 (c), /79 (!c&&c)

Full file at

Introduction to Java Unit 1. Using BlueJ to Write Programs

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

Introduction to Computer Science Unit 2. Notes

Darrell Bethea May 25, 2011

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

Software Practice 1 Basic Grammar

What did we talk about last time? Examples switch statements

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

Over and Over Again GEEN163

Programming with Java

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

1007 Imperative Programming Part II

Bjarne Stroustrup. creator of C++

Chapter 3. Selections

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

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

2.8. Decision Making: Equality and Relational Operators

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

NATIONAL UNIVERSITY OF SINGAPORE

AP Computer Science A

Oct Decision Structures cont d

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

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

Lesson 2A Data. Data Types, Variables, Constants, Naming Rules, Limits. A Lesson in Java Programming

Introduction to Computer Science Unit 2. Notes

Year 8 Computing Science End of Term 3 Revision Guide

Course Outline. Introduction to java

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

COMP 110 Project 1 Programming Project Warm-Up Exercise

St. Edmund Preparatory High School Brooklyn, NY

CS 113 PRACTICE FINAL

Topics. Chapter 5. Equality Operators

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

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

CSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:

CHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

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

When we reach the line "z = x / y" the program crashes with the message:

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

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

Motivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool

Final Exam. COMP Summer I June 26, points

Section 2.2 Your First Program in Java: Printing a Line of Text

Handout 4 Conditionals. Boolean Expressions.

Programming Assignment 2 ( 100 Points )

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

Java Bytecode (binary file)

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

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

Input. Scanner keyboard = new Scanner(System.in); String name;

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

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

Algorithms and Conditionals

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

STUDENT LESSON A12 Iterations

Introduction to Java & Fundamental Data Types

CSCI 355 Lab #2 Spring 2007

CS 251 Intermediate Programming Java Basics

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

Practice Midterm 1. Problem Points Score TOTAL 50

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

Object-oriented programming in...

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

Question: Total Points: Score:

Basic Computation. Chapter 2

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

Repe$$on CSC 121 Fall 2015 Howard Rosenthal

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

Advanced Computer Programming

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

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

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

Introduction to Arrays

Example Program. public class ComputeArea {

CSE 143, Winter 2009 Final Exam Thursday, March 19, 2009

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Transcription:

General Instructions Read and follow all directions carefully. CSCI 1226 A Test #1 Wednesday, 10 October, 2018 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. You do not need to include comments unless I specifically ask for them. You do not need to include the class declaration unless I specifically ask for it. You do not need to include import commands unless I specifically ask for them. For any question that requires input, you can assume a Scanner named kbd has already been created. You can use Sop and Sopln for System.out.print and System.out.println. There are 86 points available. You have 75 minutes to complete it. Good luck. Question Score Out of 1 6 2 8 3 6 4 12 5 6 6 10 7 6 8 6 9 12 10 4 11 10 TOTAL 1 of 8

1. [6] Declare a local variable for each of the following items. a) The height of a cannon ball above the ground. b) The mass of an ounce of gold (31.1035 grams). c) The user s name. d) What number of students passed a test. e) Whether the user answered Yes to a question. 2. [8] Circle exactly four syntax errors in the following code. For each error indicate briefly (one or two words) how to fix the problem. (The program fragment is supposed to tell us the product of 23 and 711, just as it says.) System.out.print("\n\nSimple Product\n\n") int = n; n = 23 x 711; System.out.println("23 times 711 is " n); 3. [6] Input, output, or both? (Circle the correct answer.) a) keyboard? Input Output Both b) LED? Input Output Both c) microphone? Input Output Both d) mouse? Input Output Both e) speaker? Input Output Both f) touch-screen? Input Output Both 2 of 8

4. [12] Translate the following English conditions into Java logical expressions. a) a and b are both less than 10. b) answer starts with an A or an a c) either y or z (or both) is less than 10 d) m is equal to n e) word is not equal to Yes or No. f) x plus 10 is greater than or equal to y plus z. 5. [6] Show the output of the following code: height = 4; for (int line = 1; line <= height; ++line) { for (int dot = 1; dot <= line; ++dot) { System.out.print("."); 3 of 8

6. [10] For each of the bolded method calls below, show the first line of the method definition. (Do not try to write the whole definition! Do not include the class definition.) The variables below may be used in the method calls. double x,; int n; String name; a) x = evaluate(17.1); b) show(name); c) n = morph(true, x); 7. [6] Consider the following code fragment: for (int i = 1; i <= 3; ++i) { num = kbd.nextint(); while (num < 0) { num = kbd.nextint(); System.out.println(i + " --> " + num); What will the output be if the user types (all on one line): 5-10 -5 20-30 40 20-5 -1 4 of 8

8. [6] Write a program fragment that reads an integer grade and produces the message Good. if that grade is greater than 80. 9. [12] Write a program fragment to read and verify the course number of an undergraduate computer science course at Saint Mary s University. The course number is at least 1000 but less than 5000. The program fragment should continue reading input until the user enters a valid number. When an invalid number is entered the program should notify the user and ask for another course number. For example: Enter course #: 226 That's not valid! Enter course #: 5026 That's not valid! Enter course #: 1226 OK! The user typed the numbers. The computer typed everything else. 5 of 8

10. [4] Based on your knowledge of our style guidelines, say what each of the items on the left is an example of. i) FileManager ii) handleexception iii) iv) MAX_DISKS myname a) algorithm b) class c) comment d) constant e) method f) variable 11. [10] Multiple Choice. Circle the letter of the best available answer. CPU stands for a) Canadian Programmers Union. b) Central Processing Unit. c) Central Programming Unit. d) Corporate Processing Union. e) Corporate Programming Unit. If program is expecting an integer value and user types something different (a word or a double value), the program crashes with a(n) a) ArithmeticException. b) ArrayIndexOutOfBoundsException. c) InputMismatchException. d) NullPointerException. e) NumberFormatException. What is the output of the following code int age = 15; if (age < 18) { System.out.print( Child ); if (age >= 18 && age < 65) { System.out.print( Adult ); else { System.out.print( Senior ); a) Adult b) Child c) Senior d) ChildAdultSenior e) (none of the above) 6 of 8

The mixture of English and computer language used to write algorithms is called a) variable declaration b) machine language c) pseudo-code d) digital skeuomorphism e) polymorphism When we try to create a Scanner object, we got an error shown in the figure below: What is the most likely cause of this error? a) kb should be declared final b) kb should be named kbd c) Scanner should be imported from java.util package d) Scanner should be spelled with a small s (scanner) e) System.in should be replaced by System.out Bit is short for a) basic information type. b) basic instruction type. c) binary digit. d) boolean integer type. e) byte. An algorithm is a) a program for translating high-level code into machine language. b) a program that lets other programs run on a different kind of computer. c) a set of step-by-step instructions for solving a problem. d) any computer program. e) one step in a computer program. 7 of 8

The command to read a single word from the keyboard into a String variable is: a) kbd.next(); b) kbd.nextint(); c) kbd.nextline(); d) kbd.nextstring(); e) kbd.nextword(); If you need your computer to remember a value, you need to create a) a method. b) a String. c) a variable. d) an emulator. e) an import. Suppose we have created a method that prints the message Hello! The return type of the method would be: a) double. b) int. c) static. d) String. e) void. 8 of 8