1 CSE 142 Final Exam Review Problems. 2 Question Types expressions array mystery inheritance mystery file processing array programming Critters classes.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
1 Control Structures (and user input). 2 Flow of Control The order statements are executed is called flow of control By default, statements in a method.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
1 Pre-Exam Class CSIT121 Fall 2000 Exam-II (Final Examination) TUESDAY DECEMBER 19th 8:30AM.
Loops – While, Do, For Repetition Statements Introduction to Arrays
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Java Program Statements Selim Aksoy Bilkent University Department of Computer Engineering
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved2/33 Conditionals and Loops Now we will examine programming statements.
Introduction to Java. Main() Main method is where the program execution begins. There is only one main Displaying the results: System.out.println (“Hi.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
EXAM 1 REVIEW. days until the AP Computer Science test.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
F27SA1 Software Development 1 3. Java Programming 2 Greg Michaelson.
CPS120: Introduction to Computer Science Operations Lecture 9.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Introduction to Java Java Translation Program Structure
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Chapter 2 topics Concept # on Java Subset Required for AP Exam print and println10. Testing of output is restricted to System.out.print and System.out.println.
CSE 143 Lecture 10 Recursion reading: slides created by Marty Stepp and Hélène Martin
Building java programs, chapter 3 Parameters, Methods and Objects.
By Mr. Muhammad Pervez Akhtar
CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS.  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards,
1 CSE 142 Midterm Review Problems These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or modified.
Copyright 2009 by Pearson Education Building Java Programs Chapter 9: Inheritance and Interfaces Lecture 9-2: Polymorphism reading: 9.2 self-check: #5-9.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
CS1101: Programming Methodology Preparing for Practical Exam (PE)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
CSE 143 Lecture 9: introduction to recursion reading: 12.1.
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
Midterm preview.
CompSci 230 S Programming Techniques
Lecture 9: introduction to recursion reading: 12.1
MC Question Strategies
Building Java Programs
Chapter 6 More Conditionals and Loops
CS 1428 Exam I Review.
Midterm Review Problems
Java Programming: From Problem Analysis to Program Design, 4e
slides adapted from Marty Stepp and Hélène Martin
Computers & Programming Languages
Adapted from slides by Marty Stepp, Stuart Reges & Allison Obourn.
Chapter 2: Basic Elements of Java
slides created by Marty Stepp and Alyssa Harding
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Chapter 2 Programming Basics.
slides adapted from Marty Stepp and Hélène Martin
Factoring if/else code
slides created by Marty Stepp
Building Java Programs
CS 1428 Exam I Review.
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

1 CSE 142 Final Exam Review Problems

2 Question Types expressions array mystery inheritance mystery file processing array programming Critters classes

3 Expressions 1 Precedence: unary operators !, ++, --, +, - multiplicative operators *, /, % additive operators +, - relational operators, = equality operators ==, != logical and && logical or || assignment operators =, +=, -=, *=, /= In other words :( ) before * / %, before + -, before <>, before &&, before ||

4 Expressions 2 String concatenation: same precedence as integer + -, evaluated left-to-right with other + - operations "3" "3" "33" "334" + 5 "3345" Type promotion: done as needed when int and double are mixed 50 / 6 / /

5 Expression questions Evaluate the following expressions: * 5/3 2.5 * 4 * 3/ "." + (3 + 4) + 2 * 3 482/10/5/2.0 * /5

6 Expression answers Correct answers: * 5/ * 4 * 3/ true "." + (3 + 4) + 2 * 3 "5.76" 482/10/5/2.0 * /5 11.0

7 Array mystery question public static void mystery(int[] list) { for (int i = 2; i < list.length; i++) { list[i] = list[i] + list[i - 1] + list[i - 2]; } For each call below, indicate what value is returned: Method Call Value Returned int[] a1 = {8}; mystery(a1); _______________ int[] a2 = {2, 7, 12}; mystery(a2); _______________ int[] a3 = {3, 0, 1, 4, 7}; mystery(a3); _______________ int[] a4 = {0, 1, 2, 3, 4, 5}; mystery(a4); _______________ int[] a5 = {7, 4, -10, 8, 2}; mystery(a5); _______________

8 Array mystery answer public static void mystery(int[] list) { for (int i = 2; i < list.length; i++) { list[i] = list[i] + list[i - 1] + list[i - 2]; } Method Call Value Returned int[] a1 = {8}; mystery(a1); {8} int[] a2 = {2, 7, 12}; mystery(a2); {2, 7, 21} int[] a3 = {3, 0, 1, 4, 7}; mystery(a3); {3, 0, 4, 8, 19} int[] a4 = {0, 1, 2, 3, 4, 5}; mystery(a4); {0, 1, 3, 7, 14, 26} int[] a5 = {7, 4, -10, 8, 2}; mystery(a5); {7, 4, 1, 13, 16}

9 Inheritance mystery problem public class Bat extends Foo{ public void method1() { System.out.println(“Bat 1"); } public class Foo { public void method1() { System.out.println(“Foo 1"); } public void method2() { System.out.println("Foo 2"); } public String toString() { return “Foo"; } public class Car extends Bat { public void method1() { System.out.println(“Car 1"); } public String toString() { return “Car"; } public class Squid extends Foo { public void method2() { System.out.println(“Squid 2"); } public String toString() { return “Squid"; }

10 What would be the output of the following client code? methodFooBatSquidCar method1 method2 toString Foo[] items = {new Bat(), new Car(), new Foo(), new Squid()}; for (int i = 0; i < items.length; i++) { items[i].method1(); System.out.println(items[i]); items[i].method2(); System.out.println(); }

11 What would be the output of the following client code? methodFooBatSquidCar method1Foo 1Bat 1Foo 1Car 1 method2Foo 2 Squid 2Foo 2 toStringFoo SquidCar Foo[] items = {new Bat(), new Car(), new Foo(), new Squid()}; for (int i = 0; i < items.length; i++) { items[i].method1(); System.out.println(items[i]); items[i].method2(); System.out.println(); }

12 Inheritance mystery answer Foo[] items = {new Bat(), new Car(), new Foo(), new Squid()}; for (int i = 0; i < items.length; i++) { items[i].method1(); System.out.println(items[i]); items[i].method2(); System.out.println(); } The code produces the following output: Foo Foo 2 Car 1 Car Foo 2 Foo 1 Foo Foo 2 Foo 1 Squid Squid 2

13 Programming question tips Recognize which programming tools to use to solve each problem. Repeat actions a specific number of times: for loop. Decide between several logical choices: if/else statements. Repeat an unknown number of times: while loop. Processing input a line at a time, a token at a time, or both Arrays start counting at zero. Look at for loop bounds carefully, (eg. do you mean <= or < ?) Read the problems carefully! Does it want you to print a result, or return it? What values does the method use for computation? Are these values parameters, are they read from a Scanner, etc.? What type of value (if any) does the method return? Have you handled all special cases? What if the integer is 0, or negative? What if the string has no letters? What if there is only one word in the string? Many words? Get your thoughts onto the page. A partial answer is better than none at all. Writing the correct method header will earn at least 1 point. If you can solve all of the problem except one part, leave that part blank or write what you wanted to do as a comment. Keep your eye on the clock. (Even with 1 hour and 50 minutes)