Final. Your Name CS Fall 2014 December 13, points total Your Instructor and Section

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

CSE142 Sample Midterm, Winter 2018

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

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

CIS November 14, 2017

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

! 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

CIS November 14, 2017

CS212 Midterm. 1. Read the following code fragments and answer the questions.

CSE 142 Sample Midterm Exam #2

Sequential Search (Searching Supplement: 1-2)

Arrays. What if you have a 1000 line file? Arrays

10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS

Building Java Programs A Back to Basics Approach 4th Edition Reges TEST BANK Full download at:

Question: Total Points: Score:

CS 1083 Introduction to Programming I for Computer Scientists Sample Final Questions

Building Java Programs

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

09/08/2017 CS2530 INTERMEDIATE COMPUTING 9/8/2017 FALL 2017 MICHAEL J. HOLMES UNIVERSITY OF NORTHERN IOWA TODAY S TOPIC: Exceptions and enumerations.

Building Java Programs

NoSuchElementException 5. Name of the Exception that occurs when you try to read past the end of the input data in a file.

Topic 12 more if/else, cumulative algorithms, printf

CS 112 Introduction to Programming

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

Array. Array Declaration:

Ryerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6

Building Java Programs

St. Edmund Preparatory High School Brooklyn, NY

Name CIS 201 Midterm II: Chapters 1-8

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

Some Sample AP Computer Science A Questions - Solutions

Arrays. Arrays (8.1) Arrays. One variable that can store a group of values of the same type. Storing a number of related values.

Day 2 : Intermediate Concepts 1 Examples

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Ch. 6. User-Defined Methods

Building Java Programs

Computer Programming, I. Laboratory Manual. Experiment #6. Loops

Chapter 2. Elementary Programming

CS 101 Spring 2007 Midterm 2 Name: ID:

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

CSE 142 Sample Midterm Exam #3

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

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

Object Oriented Programming. Java-Lecture 1

Topic 7 parameters. Based on slides from Marty Stepp and Stuart Reges from

Arrays. Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals

Software and Programming 1

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Zheng-Liang Lu Java Programming 45 / 79

Question: Total Points: Score:

Lesson 36: for() Loops (W11D1)

Full file at

COMP 202 Java in one week

Write a program which converts all lowercase letter in a sentence to uppercase.

Iteration: Intro. Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times. 2. Posttest Condition follows body Iterates 1+ times

CIS October 16, 2018

Practice Problems: Static & instance methods

Loops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department

Building Java Programs

COMP 202. Java in one week

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

Topic 11 Scanner object, conditional execution

CSE142 Sample Midterm Spring Name UW NetId (e.g. whitab) Section (e.g., AA) TA

Arrays. 1 Index mapping

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

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

CMPS 11 Introduction to Programming Midterm 1 Review Problems

Software and Programming 1

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

Chapter 4: Control Structures I

CSE 142 Sample Final Exam #4 (based on Autumn 2008's final)

Chapter 3. Selections

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

CIS March 1, 2018

Building Java Programs

SAMPLE EXAM Second Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 11 November 2010

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

Computação I. Exercises. Leonardo Vanneschi NOVA IMS, Universidade Nova de Lisboa. Leonardo Vanneschi Computação I NOVA IMS

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

CSE 142, Spring 2009, Final Exam

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Fundamentals of Programming Data Types & Methods

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

Common Mistakes with Functions. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

CS 231 Data Structures and Algorithms Fall Event Based Programming Lecture 06 - September 17, Prof. Zadia Codabux

Question: Total Points: Score:

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

Programming Assignment #2

Introduction to Java. Handout-3a. cs402 - Spring

CIS October 19, 2017

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

LAB 12: ARRAYS (ONE DIMINSION)

Chapter 2 Primitive Data Types and Operations. Objectives

Lecture 8 " INPUT " Instructor: Craig Duckett

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

Condi(onals and Loops

CSE 1223: Exam II Autumn 2016

There are four variables declared. They are named pearprice, pearcost, pearsales, and profit.

Transcription:

Final Your Name CS 1063 - Fall 2014 December 13, 2014 100 points total Your Instructor and Section I. (10 points, 1 point each) Match each of the terms on the left by choosing the upper case letter of the best answer on the right and putting it next to the lower case letter in the space provided. a. array b. assignment statement c. declaration d. fencepost loop e. index f. method g. parameter h. reference i. scope j. statement A. a value passed to a method B. holds multiple values of the same type C. the part of a program where a declaration is valid D. group of statements with a name E. a single command that can be executed F. the first or last value requires special processing G. specifies a variable with a name and type H. the location of an array or object I. a location in an array or String J. stores a value in a variable

CS 1063 Final page 2 II. (10 points) The following program has several errors. For each error, circle where the error occurs, label the circle with a letter: A, B, C, etc. Then for each letter, indicate how you would fix the error. import java.util.*; public class BuggyProgram { public static void main(string args) { console = Scanner(System.in); x = 5; int y; System.out.println("Enter an integer:"); y = nextint(); int z = addthem(int x, int y); System.out.println("Adding the numbers: " + x + y); System.out.println("The sum is z"); x = addthem(x,z); System.out.println("This sum is "+x); public static void addthem(x, y) { return x + y;

CS 1063 Final page 3 III. (10 points) What is printed by the following program? Mark your answer clearly. public class StringMystery { public static void main (String[] args) { String s = "ThisIsATest"; String t = "IsA"; int x = 3; int y = 5; y++; System.out.print(s.substring(x,y)); System.out.print(s.indexOf(t)); System.out.print(s.indexOf(t.toLowerCase())); System.out.print(s.charAt(y)); System.out.print(s.length()); System.out.println("Done:" + x + y);

CS 1063 Final page 4 IV. (10 points) Write a method that takes a single string as a parameter. The method prints the parameter on one line and then creates a new string which is identical to the parameter, but with all occurrences of the character a replaced with x. It prints the new string on a separate line and returns the new string.

CS 1063 Final page 5 V. (10 points) What is printed by the following program? Mark your answer clearly. public class MysteryLoops { public static void main(string[] args) { int x = 5; int y = 12; if (x + 2 < y - 5) System.out.println("This is case 1"); else System.out.println("This is case 2"); while (x < y) { System.out.println(x + " and " + y); x = x + 3; y = y + 1; System.out.println("After loop: " + x + " and " + y);

CS 1063 Final page 6 VI. (10 points) Write a complete program that prompts the user for an integer between 5 and 10 (inclusive) and then reads in that many integer values and computes and prints the average of the numbers entered. For full credit, you should continue prompting the user if an invalid value is entered and the program should never throw an exception.

CS 1063 Final page 7 VII. (10 points, 5 points each part) Consider the following two methods: public static void mystery1(int x, int y) { mystery2(x+y); if (x < y) { System.out.println(x); mystery2(2*x); else { System.out.println(y); mystery2(7*y); public static void mystery2(int z) { if (z < 10 && z > 5) System.out.print("z"); else System.out.print(z+1); System.out.println(z-2); What is printed by each of the following: a) mystery1(2,4); b) mystery1(7,4);

CS 1063 Final page 8 VIII. (10 points) Write a method called printmaxelement that takes an array of integers as a parameter and prints the elements of the array followed by the maximum of these elements. You should complete this method without calling Arrays.toString and the output should have for format shown in the examples below. int[ ] a = {-2, 5, 3, 6, 2; int[ ] b = {6, 7, 4; printmaxelement(a); printmaxelement(b); should print: The maximum of -2, 5, 3, 6, 2 is 6 The maximum of 6, 7, 4 is 7 Hint: This will require a fencepost loop.

CS 1063 Final page 9 IX. (10 points) What does the following program print out? Mark your answer clearly. import java.util.*; public class MysteryComputation { public static void main(string[] args) { int[ ] c = {-4,-2,0,2,4,; int mysteryvar=mystery(c); System.out.println(Arrays.toString(c)); System.out.println(mysteryVar); public static int mystery(int[ ] b ){ int var=0; for (int i=0; i<b.length; i++){ b[i] = b[i]+2; for (int i=0; i<b.length; i++){ var=var + b[i]; return var;

CS 1063 Final page 10 X. (10 points) Write a method, numberdaysinmonth, that takes two integer parameters, a month of the year (with January being month 1) and a year. If the month is in the range 1-12 and the year is greater than 0, it returns the number of days in the month for that year. Otherwise it returns 0. There are always 30 days in September, April, June, and November. These are the months numbered 9, 4, 6, and 11. All of the other months have 31 days, except February (month 2). February has 28 days unless it is a leap year when it has 29 days. A year is a leap year if it is divisible by 4, unless the year is also divisible by 100. Years that are divisible by 100 are leap years only when they are also divisible by 400. The year 2000 was a leap year, but the year 1900 was not.

CS 1063 Final page 11 (OVER)

CS 1063 Final page 12