Chapter 6. Repetition. Asserting Java. Rick Mercer
|
|
- Erica Andrews
- 6 years ago
- Views:
Transcription
1 Chapter 6 Repetition Asserting Java Rick Mercer
2 Algorithmic Pattern: The Determinate loop We often need to perform some action a specific number of times: Produce 89 paychecks. Count down to 0 (take 1 second of the clock). Compute grades for 81 students The determinate loop pattern repeats some action a specific number of times.
3 Pattern: Determinate Loop Problem: Do something exactly n times, where n is known in advance. Algorithm determine n repeat the following n times perform these actions Code Example: public boolean catdog(string str) { int cats = dogs = 0; int i = 0; while(i <= str.length()-3) { if(str.substring(i, i+3).equals("cat")) cats = cats + 1; if(str.substring(i, i+3).equals("dog")) dogs = dogs + 1; i++; return cats == dogs;
4 Determinate Loops with while The determinate loop pattern can be implemented with the Java while loop This template repeats a process n times: int n = /* how often we must repeat the process */ int counter = 1; while ( counter <= n ) { // the process to be repeated counter = counter + 1; determinate loops must know the number of repetitions before they begin: know exactly how many employees, or students, or whatever that must be processed, for example
5 Example for loop that produces an average Scanner keyboard = new Scanner(System.in); double sum = 0.0; double number; System.out.print("How many do you want to average? "); int n = keyboard.nextint(); int counter = 1; // Do something n times while (counter <= n) { System.out.print("Enter number: "); // <- Repeat 3 number = keyboard.nextdouble(); // <- statements sum = sum + number; // <- n times counter = counter + 1; // make sure the loop stops double average = sum / n; System.out.print("Average of "+ n + " numbers is "+ average);
6 Active Learning What is the output : int j = 1; int n = 5; while(j <= n) { System.out.print (j + " "); j = j + 1; j = 0; while(j <= 2 * n) { System.out.print (j + " "); j = j + 2;
7 Indeterminate Loops Determinate loops have a limitation We must know n (the number of repetitions) in advance Many situations need us to repeat a set of statements an unspecified number of times: Processing report cards for every student in a school (or paychecks for all employees, or...) Allowing 1 to many ATM transactions Asking the user for specific input and allowing re-entry of input after invalid inputs
8 Some things that terminate indeterminate loops An indeterminate loop repeats a process until some stopping event terminates the repetition There are many such events, but we'll focus on these: User enters a special value indicating end of data A logical expression becomes false The Grid's mover hits the wall or an edge The end of a file is encountered Indeterminate loops do not need to know n in advance Indeterminate loops can actually determine n
9 Pattern Problem Indeterminate loop Some process must repeat an unknown number of times so some event is needed to terminate the loop. Algorithm while( the termination event has not occurred ) { execute several actions1 bring the loop closer to termination Code while(dog.frontisclear()) { dog.turnleft() Example mygrid.move();
10 Example Indeterminate Loop need Grid.java // Using random robot placement, instruct robot to get to // the wall in front, turn left, and move to the next wall public class MoveAroundTheGrid { public static void main(string[] args) { Grid g = new Grid(10, 15); while (g.frontisclear()) { g.move(); g.turnleft(); while (g.frontisclear()) { g.move();
11 While loop with a Scanner Sometimes a stream of input from the keyboard or a file needs to be read until there is no more data in the input stream Consider a Scanner object constructed with a String argument The string represents an input stream You will need Scanner in ControlFun
12 These assertions public void showscanner() { Scanner scannerwithints = new Scanner("1 2 3"); assertequals(1, scannerwithints.nextint()); assertequals(2, scannerwithints.nextint()); assertequals(3, scannerwithints.nextint()); Scanner scanner = new Scanner("There are five words here."); assertequals("there", scanner.next()); assertequals("are", scanner.next()); assertequals("five", scanner.next()); assertequals("words", scanner.next()); assertequals("here.", scanner.next());
13 Write method average to return the average of the doubles in a public void testnum100s() { ControlFun cf = new ControlFun(); Scanner scanner1 = new Scanner(" "); Scanner scanner2 = new Scanner("1.0\t 2\n "); assertequals(80.0, cf.average(scanner). 0.01); assertequals(2.5, cf.average(scanner). 0.01);
14 Let sumofnegatives return the sum of the negative integers in a public void testsumofnegs() { ControlFun cf = new ControlFun(); Scanner scanner0 = new Scanner("1 2 3"); Scanner scannera = new Scanner(" "); Scanner scannerb = new Scanner(" "); assertequals(0, cf.sumofnegatives(scanner0)); assertequals(-6, cf.sumofnegatives(scannera)); assertequals(-10, cf.sumofnegatives(scannerb));
15 What's wrong with this method? public int sumofnegatives(scanner scanner) { int result = 0; while (scanner.hasnextint()) { if (scanner.nextint() < 0) { result += scanner.nextint(); return result;
Chapter 6. Repetition. Asserting Java. Rick Mercer
Chapter 6 Repetition Asserting Java Rick Mercer Algorithmic Pattern: The Determinate loop We often need to perform some action a specific number of times: Produce 89 paychecks. Count down to 0 (take 1
More informationRepetition. Chapter 6
Chapter 6 Repetition Goals This chapter introduces the third major control structure repetition (sequential and selection being the first two). Repetition is discussed within the context of two general
More informationRepetition. Chapter 6
Chapter 6 Repetition Goals This chapter introduces the third major control structure repetition (sequential and selection being the first two). Repetition is discussed within the context of two general
More informationOver and Over Again GEEN163
Over and Over Again GEEN163 There is no harm in repeating a good thing. Plato Homework A programming assignment has been posted on Blackboard You have to convert three flowcharts into programs Upload the
More informationLoops. GEEN163 Introduction to Computer Programming
Loops GEEN163 Introduction to Computer Programming Simplicity is prerequisite for reliability. Edsger W. Dijkstra Programming Assignment A new programming assignment has been posted on Blackboard for this
More informationObject Oriented Programming. Java-Lecture 6 - Arrays
Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types
More informationLesson 7 Part 2 Flags
Lesson 7 Part 2 Flags A Flag is a boolean variable that signals when some condition exists in a program. When a flag is set to true, it means some condition exists When a flag is set to false, it means
More information1 Short Answer (10 Points Each)
1 Short Answer (10 Points Each) 1. Write a for loop that will calculate a factorial. Assume that the value n has been input by the user and have the loop create n! and store it in the variable fact. Recall
More information! 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
Indefinite loops while loop! indefinite loop: A loop where it is not obvious in advance how many times it will execute.! We often use language like " "Keep looping as long as or while this condition is
More informationProblem Solving With Loops
To appreciate the value of loops, take a look at the following example. This program will calculate the average of 10 numbers input by the user. Without a loop, the three lines of code that prompt the
More informationChapter 4: Control structures. Repetition
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
More informationChapter 4: Control structures
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
More informationRepetition, Looping. While Loop
Repetition, Looping Last time we looked at how to use if-then statements to control the flow of a program. In this section we will look at different ways to repeat blocks of statements. Such repetitions
More informationEvaluating the Style of your programs
Evaluating the Style of your programs Objectives At the end of this exercise, students will: Roles Be able to evaluate a program for conformance to style guide for the class. Be able to evaluate arithmetic
More informationThe for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming
The for Loop, Accumulator Variables, Seninel Values, and The Random Class CS0007: Introduction to Computer Programming Review General Form of a switch statement: switch (SwitchExpression) { case CaseExpression1:
More informationLoops. CSE 114, Computer Science 1 Stony Brook University
Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?
More informationIntroduction to Computer Science I Spring 2010 Sample mid-term exam Answer key
Introduction to Computer Science I Spring 2010 Sample mid-term exam Answer key 1. [Question:] (15 points) Consider the code fragment below. Mark each location where an automatic cast will occur. Also find
More informationCOMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements
COMP-202 Unit 4: Programming With Iterations CONTENTS: The while and for statements Introduction (1) Suppose we want to write a program to be used in cash registers in stores to compute the amount of money
More informationMaximization and Minimization Problems. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington
Maximization and Minimization Problems CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Maximization Problems Given a set of data, we want to find
More informationProgram Control Flow
Lecture slides for: Chapter 3 Program Control Flow Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2
More informationProgram Control Flow
Lecture slides for: Chapter 3 Program Control Flow Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-4: do/while loops, assertions reading: 5.1, 5.5 1 The do/while loop do/while loop: Performs its test at the end of each repetition. Guarantees that the loop's
More informationCSC 1051 Villanova University. CSC 1051 Data Structures and Algorithms I. Course website:
Repetition CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this
More informationPlease answer the following questions. Do not re-code the enclosed codes if you have already completed them.
Dec. 9 Loops Please answer the following questions. Do not re-code the enclosed codes if you have already completed them. What is a loop? What are the three loops in Java? What do control structures do?
More informationLecture 8 " INPUT " Instructor: Craig Duckett
Lecture 8 " INPUT " Instructor: Craig Duckett Assignments Assignment 2 Due TONIGHT Lecture 8 Assignment 1 Revision due Lecture 10 Assignment 2 Revision Due Lecture 12 We'll Have a closer look at Assignment
More informationProgramming Project: ArrayFun
Programming Project: ArrayFun Collaboration: Solo with help from classroom/online resources, Lane, and/or Rick. Anyone can also share thoughts about any specification and possible algorithm, but no sharing
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 000 Spring 2014 Name (print):. Instructions Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationTop-Down Program Development
Top-Down Program Development Top-down development is a way of thinking when you try to solve a programming problem It involves starting with the entire problem, and breaking it down into more manageable
More informationRepe$$on CSC 121 Spring 2017 Howard Rosenthal
Repe$$on CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Learn the following three repetition structures in Java, their syntax, their similarities and differences, and how to avoid common errors when
More informationCSC 1051 Data Structures and Algorithms I
Repetition CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-4: do/while loops, assertions reading: 5.1, 5.5 1 The do/while loop do/while loop: Performs its test at the end of each repetition. Guarantees that the loop's
More informationRepetition CSC 121 Fall 2014 Howard Rosenthal
Repetition CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while
More informationRepe$$on CSC 121 Fall 2015 Howard Rosenthal
Repe$$on CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics
WIT COMP1000 Java Basics Java Origins Java was developed by James Gosling at Sun Microsystems in the early 1990s It was derived largely from the C++ programming language with several enhancements Java
More informationWhat two elements are usually present for calculating a total of a series of numbers?
Dec. 12 Running Totals and Sentinel Values What is a running total? What is an accumulator? What is a sentinel? What two elements are usually present for calculating a total of a series of numbers? Running
More information1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?
CIS 3022 Prog for CIS Majors I February 10, 2009 Exam I Print Your Name Your Section # Total Score Your work is to be done individually. The exam is worth 105 points (five points of extra credit are available
More informationCOMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz
COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz The in-class quiz is intended to give you a taste of the midterm, give you some early feedback about
More informationBjarne Stroustrup. creator of C++
We Continue GEEN163 I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone. Bjarne Stroustrup creator
More informationThere are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do:
Project MindNumber Collaboration: Solo. Complete this project by yourself with optional help from section leaders. Do not work with anyone else, do not copy any code directly, do not copy code indirectly
More informationCSE142 Sample Midterm Spring Name UW NetId (e.g. whitab) Section (e.g., AA) TA
CSE142 Sample Midterm Spring 2018 Name UW NetId (e.g. whitab) Section (e.g., AA) TA This exam is divided into nine questions with the following points: # Problem Area Points Score ---------------------------------------------
More informationJava Classes: Random, Character A C S L E C T U R E 6
Java Classes: Random, Character A C S - 1903 L E C T U R E 6 Random An instance of the Random can be used to generate a stream of random values Typical process: 1. Create a Random object 2. Use the object
More informationConditional Programming
COMP-202 Conditional Programming Chapter Outline Control Flow of a Program The if statement The if - else statement Logical Operators The switch statement The conditional operator 2 Introduction So far,
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationCMPT 125: Lecture 4 Conditionals and Loops
CMPT 125: Lecture 4 Conditionals and Loops Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 17, 2009 1 Flow of Control The order in which statements are executed
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasketEnhanced { public static void main(string[]
More informationControls Structure for Repetition
Controls Structure for Repetition So far we have looked at the if statement, a control structure that allows us to execute different pieces of code based on certain conditions. However, the true power
More informationMidterm Examination (MTA)
M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and
More informationIntroduction to Software Development (ISD) Week 3
Introduction to Software Development (ISD) Week 3 Autumn term 2012 Aims of Week 3 To learn about while, for, and do loops To understand and use nested loops To implement programs that read and process
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationChapter 6. Repetition Statements. Animated Version The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 6 Repetition Statements Animated Version required for reproduction or display. Chapter 6-1 Objectives After you have read and studied this chapter, you should be able to Implement repetition control
More informationChapter 5 Lab Methods
Chapter 5 Lab Methods Lab Objectives Be able to write methods Be able to call methods Be able to write javadoc comments Be able to create HTML documentation using the javadoc utility Introduction Methods
More informationCSC 1051 Data Structures and Algorithms I
Repetition CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this
More informationAnatomy of a Java Program: Comments
CS149 Anatomy of a Java Program: Comments Javadoc comments: /** * Application that converts inches to centimeters. * * @author Alvin Chao * @version 01/21/2014 */ Everything between /** and */ ignored
More informationJava Coding 3. Over & over again!
Java Coding 3 Over & over again! Repetition Java repetition statements while (condition) statement; do statement; while (condition); where for ( init; condition; update) statement; statement is any Java
More informationLinked Lists. private int num; // payload for the node private Node next; // pointer to the next node in the list }
Linked Lists Since a variable referencing an object just holds the address of the object in memory, we can link multiple objects together to form dynamic lists or other structures. In our case we will
More informationSTUDENT LESSON A12 Iterations
STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of
More informationIntroduction to Computer Science Unit 2. Notes
Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and
More informationFOR INTERNAL SCRUTINY (date of this version: 17/2/2016) UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS
UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS SOFTWARE TESTING Tuesday 1 st April 2014 00:00 to 00:00 INSTRUCTIONS TO CANDIDATES Answer QUESTION 1 and ONE other question.
More informationC212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.
C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What
More informationFundamentals of Programming Data Types & Methods
Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators
More informationHandout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops.
Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8 Handout 5 Loops. Loops implement repetitive computation, a k a iteration. Java loop statements: while do-while for 1. Start with the while-loop.
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Methods
Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Methods As programmers, we often find ourselves writing the same or similar code over and over. We learned that we can place code
More informationMenu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:
Menu Driven Systems While loops, menus and the switch statement Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list while loops recap
More informationMcGill University School of Computer Science COMP-202A Introduction to Computing 1
McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif
More informationSt. Edmund Preparatory High School Brooklyn, NY
AP Computer Science Mr. A. Pinnavaia Summer Assignment St. Edmund Preparatory High School Name: I know it has been about 7 months since you last thought about programming. It s ok. I wouldn t want to think
More informationOct Decision Structures cont d
Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements
More informationChapter 3. Selections
Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of
More informationCOMP 202. Programming With Iterations. CONTENT: The WHILE, DO and FOR Statements. COMP Loops 1
COMP 202 Programming With Iterations CONTENT: The WHILE, DO and FOR Statements COMP 202 - Loops 1 Repetition Statements Repetition statements or iteration allow us to execute a statement multiple times
More informationCOE 211/COE 212 Computer/Engineering Programming. Welcome to Exam II Thursday December 20, 2012
1 COE 211/COE 212 Computer/Engineering Programming Welcome to Exam II Thursday December 20, 2012 Instructor: Dr. George Sakr Dr. Wissam F. Fawaz Dr. Maurice Khabbaz Name: Student ID: Instructions: 1. This
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationFlow of Control: Loops. Chapter 4
Flow of Control: Loops Chapter 4 Java Loop Statements: Outline The while statement The do-while statement The for Statement Java Loop Statements A portion of a program that repeats a statement or a group
More informationCMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING
CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING INPUT AND OUTPUT Input devices Keyboard Mouse Hard drive Network Digital camera Microphone Output devices.
More informationLecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18
Assignment Lecture 9 Logical Operations Formatted Print Printf Increment and decrement Read through 3.9, 3.10 Read 4.1. 4.2, 4.3 Go through checkpoint exercise 4.1 Logical Operations - Motivation Logical
More informationExam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:
كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this
More informationHandout 4 Conditionals. Boolean Expressions.
Handout 4 cs180 - Programming Fundamentals Fall 17 Page 1 of 8 Handout 4 Conditionals. Boolean Expressions. Example Problem. Write a program that will calculate and print bills for the city power company.
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationCONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops
COMP-202 Unit 4: Programming with Iterations Doing the same thing again and again and again and again and again and again and again and again and again... CONTENTS: While loops Class (static) variables
More informationDarrell Bethea May 25, 2011
Darrell Bethea May 25, 2011 Yesterdays slides updated Midterm on tomorrow in SN014 Closed books, no notes, no computer Program 3 due Tuesday 2 3 A whirlwind tour of almost everything we have covered so
More informationSFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS
SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS Day Class Midterm Exam Dr. R. Khedri DURATION : 50 minutes McMaster University Midterm Exam (CAS) October 29, 2012 Please CLEARLY print: NAME:
More informationBasic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java
Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection
More informationChapter 4: Control Structures I
Chapter 4: Control Structures I Java Programming: From Problem Analysis to Program Design, Second Edition Chapter Objectives Learn about control structures. Examine relational and logical operators. Explore
More informationJava. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures
Chapter 5: Control Structures II Java Programming: Program Design Including Data Structures Chapter Objectives Learn about repetition (looping) control structures Explore how to construct and use count-controlled,
More information1 Short Answer (5 Points Each)
1 Short Answer (5 Points Each) 1. What are the three types of programming errors? Briefly describe each of them. Syntax Error: An error in the program code due to misuse of the programming language. Run-time
More informationCS 112 Introduction to Programming
CS 112 Introduction to Programming Program Analysis Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu Admin q PS5 Walkthrough Thursday
More informationCOE 212 Engineering Programming. Welcome to Exam II Tuesday November 28, 2018
1 COE 212 Engineering Programming Welcome to Exam II Tuesday November 28, 2018 Instructors: Dr. Dima El-khalil Dr. Jawad Fahs Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam
More informationChapter 1 Lab Algorithms, Errors, and Testing
Chapter 1 Lab Algorithms, Errors, and Testing Lab Objectives Be able to write an algorithm Be able to compile a Java program Be able to execute a Java program using the Sun JDK or a Java IDE Be able to
More informationCOMP 110 Programming Exercise: Simulation of the Game of Craps
COMP 110 Programming Exercise: Simulation of the Game of Craps Craps is a game of chance played by rolling two dice for a series of rolls and placing bets on the outcomes. The background on probability,
More informationLast Class. While loops Infinite loops Loop counters Iterations
Last Class While loops Infinite loops Loop counters Iterations public class January31{ public static void main(string[] args) { while (true) { forloops(); if (checkclassunderstands() ) { break; } teacharrays();
More informationClaremont McKenna College Computer Science
Claremont McKenna College Computer Science CS 51 Handout 4: Problem Set 4 February 10, 2011 This problem set is due 11:50pm on Wednesday, February 16. As usual, you may hand in yours until I make my solutions
More informationCOMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 Announcements Midterm Exams on 4 th of June (12:35 14:35) Room allocation will be announced soon
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops reading: 4.1, 5.1 self-check: Ch. 4 #2; Ch. 5 # 1-10 exercises: Ch. 4 #2, 4, 5, 8; Ch. 5 # 1-2 Copyright 2009
More informationIntroduction to Computer Science Unit 2. Notes
Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and
More informationLecture 17. Instructor: Craig Duckett. Passing & Returning Arrays
Lecture 17 Instructor: Craig Duckett Passing & Returning Arrays Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) GRADED! Section 1: Monday, January 22 nd Assignment 2 (LECTURE 8) GRADED! Section
More informationCompSci 125 Lecture 11
CompSci 125 Lecture 11 switch case The? conditional operator do while for Announcements hw5 Due 10/4 p2 Due 10/5 switch case! The switch case Statement Consider a simple four-function calculator 16 buttons:
More informationNew York University Introduction to Computer Science Midterm2 Sample Problems 2013 Andrew I. Case. Instructions:
Name: New York University Introduction to Computer Science Midterm2 Sample Problems 2013 Andrew I. Case Instructions: KEEP TEST BOOKLET CLOSED UNTIL YOU ARE INSTRUCTED TO BEGIN. This exam is double sided
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void
More informationProgramming Project: Game of Life
Programming Project: Game of Life Collaboration Solo: All work must be your own with optional help from UofA section leaders The Game of Life was invented by John Conway to simulate the birth and death
More informationWarm up Exercise. What are the types and values of the following expressions: * (3 + 1) 3 / / 2.0 (int)1.0 / 2
Warm up Exercise What are the types and values of the following expressions: 3.0+4 * (3 + 1) 3 / 2 + 1.0 1.0 / 2.0 (int)1.0 / 2 COMP-202 - Programming Basics 1 Warm up Exercise What are the types and values
More informationCSIS 10A Assignment 4 SOLUTIONS
CSIS 10A Assignment 4 SOLUTIONS Calculator.java Name: Naomi Lyles Approximate completion time: 20 minutes References: None Write a description of class Calculator here. @author (your name) @version (a
More informationCSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010
CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010 Name: Section: TA: Student ID #: You have 50 minutes to complete this exam. You may receive a deduction if you keep working after the instructor
More information