CSCE 145, Sections 4, 5, 6 Study Guide Second Midterm

Similar documents
APCS Semester #1 Final Exam Practice Problems

Introduction to Programming Using Java (98-388)

Text Input and Conditionals

Absolute C++ Walter Savitch

Course Outline. Introduction to java

Chapter 4. Defining Classes I

T H E I N T E R A C T I V E S H E L L

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Programming for Engineers Introduction to C

Midterms Save the Dates!

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Chapter 2, Part I Introduction to C Programming

Problem Solving with C++

IS12 - Introduction to Programming. Lecture 7: Introduction to C

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

One of Mike s early tests cases involved the following code, which produced the error message about something being really wrong:

COP 1220 Introduction to Programming in C++ Course Justification

About this exam review

analogwrite(); The analogwrite function writes an analog value (PWM wave) to a PWM-enabled pin.

C: How to Program. Week /Mar/05

"Hello" " This " + "is String " + "concatenation"

Typescript on LLVM Language Reference Manual

Language Reference Manual

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

Software Design and Analysis for Engineers

CS 142 Style Guide Grading and Details

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

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.

MITOCW watch?v=0jljzrnhwoi

Chapter 4. Defining Classes I

Language Reference Manual

CS 240 Final Exam Review

Chapter 2 - Introduction to C Programming

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

How to approach a computational problem

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.

Java+- Language Reference Manual

In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability. programs into their various phases.

Loop structures and booleans

Syntax Errors; Static Semantics

CS112 Lecture: Working with Numbers

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

CSE 142 Su 04 Computer Programming 1 - Java. Objects

Unit 3. Operators. School of Science and Technology INTRODUCTION

Introduction to Computer Science Midterm 3 Fall, Points

Documentation Requirements Computer Science 2334 Spring 2016

If you don t, it will return the same thing as == But this may not be what you want... Several different kinds of equality to consider:

Programming Basics. Part 1, episode 1, chapter 1, passage 1

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

Chapter 4 Defining Classes I

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

Repe$$on CSC 121 Spring 2017 Howard Rosenthal


Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

COMP 250 Winter 2011 Reading: Java background January 5, 2011

1 Lexical Considerations

Introduction to Java & Fundamental Data Types

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Midterms Save the Dates!

Basics of Java Programming

Introduction to Computer Programming for Non-Majors

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

C-LANGUAGE CURRICULAM

Add Subtract Multiply Divide

More Programming Constructs -- Introduction

Variables. Data Types.

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

General Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j;

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

2 nd Week Lecture Notes

Java Primer 1: Types, Classes and Operators

Fundamentals of Programming Session 4

CISC-124. Casting. // this would fail because we can t assign a double value to an int // variable

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CS50 Supersection (for those less comfortable)

Special Section: Building Your Own Compiler

CS16 Week 2 Part 2. Kyle Dewey. Thursday, July 5, 12

DEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A

Chapter 3: Operators, Expressions and Type Conversion

S O R T I N G Sorting a list of elements implemented as an array. In all algorithms of this handout the sorting of elements is in ascending order

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

CS3 Fall 05 Midterm 1 Standards and Solutions

Practice exam for CMSC131-04, Fall 2017

PLT Fall Shoo. Language Reference Manual

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

COMP 202 Java in one week

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Programming with C++ Language

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

CS Introduction to Data Structures How to Parse Arithmetic Expressions

Transcription:

Chapter 5 CSCE 145, Sections 4, 5, 6 Study Guide Second Midterm Miscellaneous This chapter covers the basics of fence post errors, which you should be able to explain. This chapter also covers the issue of the scope of temporary variables, as in the question, what s wrong with the following code? public class ThisClass extends Object public ThisClass() // either add or subtract, depending on the last parameter public int myincrement(int invalue, int theaddin, boolean additinq) int thisvalue; if(additinq) thisvalue += theaddin; else thisvalue -= theaddin; return thisvalue; // public int MyMethod1(int invalue) // always add in the increment value public int MyIncrement(int invalue, int theaddin) thisvalue += theaddin; return thisvalue; // public void MyMethod2(int invalue2) // public class ThisClass extends Object The switch statement has not been covered and essentially will not be covered. (You are free to use it, or free to ignore it and just use if-else if statements.) 1

You should know how to nest and cascade if statements, and you should know what happens if you dangle the else because you didn t use braces (page 250). (I will not, repeat not, do a trick question on this. I do not expect you to be able to read the intricacies of bad code, but I do expect you to be able to write correct nested/cascaded if statements.) Patterns, pp. 257ff. Loop and a half You should be able to write a loop with an initial segment before the steady state of the loop iteration. You should be able to write a loop with a final segment after the steady state of the loop iteration. Temporary variable You should be able to write a for or while loop with a counter that is incremented or referenced only when an if statement happens to be true. Counting pattern You should be able to write a while loop with a counter that is always incremented inside each iteration. for loops versus while loops You should know when a for loop is more appropriate than a while loop, and vice versa. Boolean expressions You should be able to write a correct boolean expression or series of expressions. Again, I will not play games with asking you for evaluating an expression that has no parentheses. You should be writing your expressions with adequate parentheses to make the order of evaluation crystal clear, and you should recognize the absence of parentheses to be inherently evil. General Comments You should be able to write simple methods that do not return a value, such as public void mymethod() // public void mymethod() as and you should be able to write simple methods that do return a value, such 2

public String myothermethod() String returnvalue; returnvalue = "pneumonoultramicroscopicsilicovolcanoconiosis"; return returnvalue; // public String myothermethod() Chapter 6 You should be able to write multiple constructors for a class, to know why and when you can do this, and why you would want to do this. You should know the proper (proper in this case being interpreted under Buell s strict rules) use of this and of accessor and mutator methods. You should be able to explain the use of final and you should be able to explain what happens when one uses static final as in the two routines in the Utilities.java modules in the examples I gave you. I have decided that I will give you one page that contains the code for the ScannerOpen and the PrintWriterOpen methods. That way, I can expect you to be able to use those methods and understand what they do without requiring you to be able to reproduce those methods. You should read and thoroughly understand the bottom of page 309 on the use of temporary versus instance variables. Arithmetic, Input, and Output We covered some material on arithmetic and on input and output that is not in Chapters 5 through 8. This material is in fact on the exam. You should be able to write correct code for output using System.out.println(stuff); You should be able to tell me the effect of a statement such as System.out.printf("%d ZZZZ %f YYYY %s%n",i,x,thestring);. (An acceptable answer is: This prints the value of i, assuming that i is an int variable, then the string ZZZZ with a blank space on each side, then the value of x as a floating point number, assuming that x is a float or double variable, then the string YYYY with a blank space on either side, and then the string thestring, followed by a newline so that the next line of output would start on the next line. ) Note: I will not, repeat not, expect you to parrot back the intricacies of output of floating point numbers using something like System.out.printf("%11.4f%n",-1234567.890123);. 3

Chapter 7 As mentioned above, you should know about different numeric data types and about character, boolean, and String variables. You should know the syntax of the methods on page 350, but you do not need to know the syntax of the million and one other methods for a String variable. Accessors and mutators, yes. Chapter 8 If given a piece of code similar to the Person class in the text, you should be able to create a simple class like the DateTime class so that the original code could be simplified. You should be able to deal with try - catch for exception handling. (And remember, you ll have an example of this in the sample code for the Utilities.java class.) General Comment There are a great many things about programming that require remembering specific and detailed rules. This include: Exactly what the precedence order is for evaluating boolean or arithmetic expressions without any parentheses. Exactly what gets printed in something like a %12.7f format if, for some reason, this format isn t going to provide complete accuracy for the numbers being printed. Exactly what substring is extracted from a string using one of the particular methods in the String class. (This is included here because the method public String substring(int beginindex, int endindex) returns a new string that is a substring of this string, begining at the specified beginindex and extending to the character at index endindex - 1, so the trick is to remember the minus one. In these and similar contexts, what I expect you to be able to do is the following. You should recognize any and all instances of this sort of thing as places where arcane and specific rules are in effect and you need to be especially careful to get it right. You should be able to find the reference information that says exactly how to do it right. 4

You need not be able to tell me exactly what happens in an instance in which there might be a problem, but you should be able to recognize that a problem might exist. If you follow this approach, then you will be able to write correct code yourself, and you will be able to recognize instances in other people s code where there might be a problem. Remember that debugging a program is an empirical process and not a metaphysical process. That is, when a program is not producing the correct output it s because it is doing something different from what you intended. The first and most important debugging step is to find out what in fact the program is doing, not to sit back and contemplate the philosophical or moral nature of the program as written. 5