EXAM 1 REVIEW. days until the AP Computer Science test.

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

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
03 Data types1June Data types CE : Fundamental Programming Techniques.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Java Intro. Strings “This is a string.” –Enclosed in double quotes “This is “ + “another “ + “string” –+ concatenates strings “This is “ “ string”
Loops – While, Do, For Repetition Statements Introduction to Arrays
Loops Repeat after me …. Loops A loop is a control structure in which a statement or set of statements execute repeatedly How many times the statements.
FIT Objectives By the end of this lecture, students should: understand iteration statements understand the differences of for and while understand.
Strings as objects Strings are objects. Each String is an instance of the class String They can be constructed thus: String s = new String("Hi mom!");
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Loops Chapter 4. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while” structures.
Introduction to Java. Main() Main method is where the program execution begins. There is only one main Displaying the results: System.out.println (“Hi.
Agenda Review User input Scanner Strong type checking Other flow-control structures switch break & continue Strings Arrays 2.
Building Java Programs Chapter 5 Program Logic and Indefinite Loops Copyright (c) Pearson All rights reserved.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapters 3-4: Using Objects.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Java Fundamentals Asserting Java Chapter 2: Introduction to Computer Science ©Rick Mercer.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
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.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
CSC1401 Strings (text). Learning Goals Working with Strings as a data type (a class) Input and output of Strings String operations.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
String Definition A String is a set of characters that behaves as a single unit. The characters in a String include upper-case and lower-case letters,
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
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.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CSC Programming I Lecture 9 September 11, 2002.
Building java programs, chapter 3 Parameters, Methods and Objects.
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.
Cumulative algorithms. 2 Adding many numbers How would you find the sum of all integers from ? // This may require a lot of typing int sum = 1 +
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
1 CSE 142 Final Exam Review Problems. 2 Question Types expressions array mystery inheritance mystery file processing array programming Critters classes.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
1 BUILDING JAVA PROGRAMS CHAPTER 5 PROGRAM LOGIC AND INDEFINITE LOOPS.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Input, Output and Variables GCSE Computer Science – Python.
Building Java Programs Chapter 7 Arrays Copyright (c) Pearson All rights reserved.
(Dreaded) Quiz 2 Next Monday.
CS 160 – Summer 16 Exam 1 Prep.
[ 4.00 ] [ Today’s Date ] [ Instructor Name ]
String class.
Introduction to Computer Science / Procedural – 67130
Conditional Execution
Goals Understand how to create and compare Strings.
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Building Java Programs
Goals Understand how to create and compare Strings.
An Introduction to Java – Part I, language basics
Goals Understand how to create and compare Strings.
Chapter 2: Basic Elements of Java
Building Java Programs
Building Java Programs
python.reset() Also moving to a more reasonable room (CSE 403)
Building Java Programs
Using Objects (continued)
Building Java Programs
Repetition Statements
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Presentation transcript:

EXAM 1 REVIEW

days until the AP Computer Science test

Test Taking Skills Read questions carefully, look for exactly what is being asked. Scan the entire test to understand what parts look easy and what parts are worth the most points. Never leave questions blank. Write down anything you can think of that is relevant. Blank answers can’t get partial credit. Pace yourself. Don’t spend lots of time on a question worth only a few points if you still need to do a question worth lots of points.

Exam Review 1. All the following are primitive data types: int, char, double, boolean, String a) TRUE b) FALSE

Exam Review 2. The following is an example of an implicit cast: int a = (int) (5.0 / 9.0); a) TRUE b) FALSE

Explicit cast vs. implicit cast An implicit cast occurs when the cast is automatically done by the compiler and no code is required. int i = 3; double d = 3; public static compute(double d) {…} compute(42); An explicit cast requires code from the programmer to inform the compiler of the cast. int i = (int)(Math.sqrt(2));

Exam Review 3. The concatenation operator is the plus sign. a) TRUE b) FALSE

Exam Review 4. Adding a double and an int implicitly converts the int variable to a double and the sum is a double. a) TRUE b) FALSE

Exam Review int a = 9; int b = 5; for (int i = 0; i <= a; i++) { b = b + i; a = a - i; } a = b = i = WALKTHROUGH

Exam Review 5. What are the values of a and b after the following code is executed? int a = 9; int b = 5; for (int i = 0; i <= a; i++) { b = b + i; a = a - i; } a) a = -36, b = 9 b) a = -36, b = 50 c) a = 3, b = 11 d) a = 9, b = 50 e) a = 9, b = 11

Exam Review 6. What is the output of the following code? for (int i = 1; i < 3; i++) { for (int j = 3; j > i; j--) { System.out.print(i+j + " "); } a) b) c) d) e)

Exam Review 7. Which code will produce the following output? The quick brown fox jumped over the lazy dog. I. System.out.print(“The quick brown fox\njumped over the lazy dog.”); II. System.out.print(“The quick brown fox”); System.out.println(“jumped over the lazy dog.”); III. System.out.print(“The quick brown fox”); System.out.print(“jumped over the lazy dog.”); a) None b) I only c) II only d) III only e) I and II only f) I, II, and III

Exam Review public static int method() { int a; for (a = 1; a <= 3; a++) { a = (int)Math.pow(2, a); } return a; } a = WALKTHROUGH

Exam Review 8. What does the following method return? public static int method() { int a; for (a = 1; a <= 3; a++) { a = (int)Math.pow(2, a); } return a; } a) 1 b) 4 c) 8 d) 9

Exam Review public class Program { public static void main(String[] args) { int a = 1; int b = 2; swap(a, b); System.out.println(a + " " + b + " "); } public static void swap(int a, int b) { a = b; b = a; System.out.print(a + " " + b + " "); } a = b = a = b = Console: WALKTHROUGH

Exam Review 9. What is the output of the following program? public class Program { public static void main(String[] args) { int a = 1; int b = 2; swap(a, b); System.out.println(a + " " + b + " "); } public static void swap(int a, int b) { a = b; b = a; System.out.print(a + " " + b + " "); } a) b) c) d) e)

Exam Review 10. What is the output of the following code? String str = "This is a string."; String newStr = str.substring(str.indexOf('s'), str.indexOf('g')); System.out.println(newStr); int indexOf(String str) Returns the index within this string of the first occurrence of the specified substring. String substring(int beginIndex, int endIndex) Returns a new string that is a substring of this string, from beginIndex to endIndex (not including the character at endIndex).

Exam Review 10. What is the output of the following code? String str = "This is a string."; String newStr = str.substring(str.indexOf('s'), str.indexOf('g')); System.out.println(newStr); a) s is a strin b) s is a string c) strin d) string

Exam Review 1. For each expression in the left-hand column, indicate its value in the right-hand column. Be sure to list a constant of appropriate type (e.g., 7.0 rather than 7 for a double, Strings in quotes). (Note that all are worth 3 points except for a, which is worth 2 points) a * 5/3 b. 2.1 * * (3/12) c. 75 % % % 3 d. 2 * 3 + "." + (8 + 4) + 3 * 3 e. 982/10/10/2.0 * /5 f % 10 % 10 g “+”

Exam Review * 5/3 2.1 * * (3/12) / * *

Exam Review 75 % % % 3 2 * 3 + "." + (8 + 4) + 3 * * 3 + “.” * “.” “6.” “6.12” + 9 “6.129”

Exam Review 982/10/10/2.0 * /5 98 / 10 / 2.0 * / 5 9 / 2.0 * / * /

Exam Review 9768 % 10 % “+” % “+” “5+” “5+3” + 2 “5+32”

Exam Review 2. (12 points) What is the output of the following program? pubic static void main (String args[]) { int one = 1; int two = 2; double three = 3.0; one = theMethod (one, 2, three) + theMethod (1, two, 1.0) + theMethod(one, two, three); System.out.println("one + two is " + (one + two)); } public static int theMethod(int one, int two, double three) { int returnValue = (int) (one + two - three); System.out.println(returnValue); return returnValue; }

Exam Review pubic static void main (String args[]) { int one = 1; int two = 2; double three = 3.0; one = ; System.out.println("one + two is " + (one + two)); } public static int theMethod(int one, int two, double three) { int returnValue = (int) (one + two - three); System.out.println(returnValue); return returnValue; } WALKTHROUGH

Exam Review one + two is 4 Rubric 3 points for each correct line of output 1 point for having “one + two is” in your answer

Exam Review 3. (18 points) The usual rules for changing standard English into Pig Latin are as follows: For words that begin with a consonant, the initial consonant is moved to the end of the word, and "ay" is added, as in the following examples: "happy" → "appyhay" "duck" → "uckday” For words that begin with a vowel, you just add "way" to the end. Examples: "egg" → "eggway" "inbox" → "inboxway" Write 2 methods which convert an English word to Pig Latin. Both methods take an input parameter which is a single English word. The method should return the Pig Latin word. Do not worry about other Pig Latin rules for this question.

Exam Review public static String englishToPigLatin_ConsonantAtStart( String englishWord) { return word.substring(1) + return.charAt(0) + “ay”; } Rubric: 1 point for using substring(), 3 for getting it correct. 1 point for using charAt(), 3 for getting first char correctly. May use substring(0,1) for full credit. 1 point for concatenating the “ay” strings together, 3 for concatenating correctly. 1 point for using the return statement to return a string, 3 points for returning the correct string

Exam Review public static String englishToPigLatin_VowelAtStart( String englishWord) { return word + “way”; } Rubric: 1 point for concatenating the “way” strings together, 3 for concatenating correctly. 1 point for using the return statement to return a string, 3 points for returning the correct string.

Exam Review public static String englishToPigLatin_VowelAtStart( String englishWord) { return word + “way”; } Rubric: 1 point for concatenating the “way” strings together, 3 for concatenating correctly. 1 point for using the return statement to return a string, 3 points for returning the correct string.

Exam Review 4. (20 points) Write a program which reads the size of a triangle from standard input and prints a "number triangle" of that size, as per the following examples: Size of triangle: Size of triangle:

Exam Review public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print(“enter triangle size: “); int size = console.nextInt(); triangles(size); console.close(); } Rubric 2 points for correctly declaring the Scanner. 1 point for trying to declare a scanner. 1 points for closing the Scanner. 2 points for user prompt. 2 points for reading in an integer from the Scanner. 1 point for calling console.nextInt(). 1 for assigning to an int correctly.

Exam Review public static void triangles(int n) { for (int i = n; i > 0; i--) { for (int j = i; j > 0; j--) { System.out.print(j); } System.out.println(); } Rubric 6 points for correct outer for loop -2 points each for the initialization, test and update of the for loop 6 points for inner inner for loop -2 points each for the initialization, test and update of the for loop If done incorrectly, 1 point for each for-loop they have. 1 point for the correct output

Homework Read 3.1 Self Check 4.1, 4.2, 4.4, 4.5, 4.6, 4.13, 4.14 Exercise 4.3, 4.4 FracCalc Checkpoint 1