1. Trang chủ
  2. » Ngoại Ngữ

Barron''''''''s AP Computer Sciece 7th Edition

508 124 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Front Cover

  • Copyright

  • Contents

  • Preface

  • Introduction

  • PRACTICE EXAM ONE / DIAGNOSTIC TEST

  • Introductory Java Language Features

  • Classes and Objects

  • Inheritance and Polymorphism

  • Some Standard Classes

  • Program Design and Analysis

  • Arrays and Array Lists

  • Recursion

  • Sorting and Searching

  • The AP Computer Science A Labs

  • Practice Exam Two

  • Practice Exam Three

  • Appendix: Glossary of Useful Computer Terms

  • Index

  • Back Cover

Nội dung

AP COMPUTER SCIENCE A For 70 years, BARRON’S experts have been helping students surpass their expectations on standardized tests This is the only book you will need to get the score you want on the AP Computer Science A test 4P  roven test-taking strategies that make the difference between a good score and a great score 4O  ne full-length diagnostic test to help you pinpoint your strengths and weaknesses 4T  wo additional full-length practice tests to boost your confidence 4T  he most up-to-date subject review that covers the specific material you need to know for the test ONLINE See inside front cover for details 4A  ccess to a full-length sample AP Computer Science A exam with answer explanations and automatic scoring BARRON’S GIVES YOU THE ANSWERS! Every question in this book comes with a comprehensive answer explanation AP * COMPUTER SCIENCE A MOST UP-TO-DATE REVIEW AND PRACTICE TESTS CURRENTLY AVAILABLE 7TH EDITION Roselyn Teukolsky, M.S n 4 full-length practice tests with explained answers, including one online n Expert advice on the best way to approach the test n Review covers all relevant topics, including the new AP Computer Science A labs and changes to the Java subset BOOK EAN $18.99 Canada $21.99 w w w.b a r r o nseduc.co m PRINTED IN THE USA 7TH EDITION STUDYGREEN Printed on partially recycled paper Fully recyclable 4-0594-AP-ComputerScienceA-fbs.indd All Pages The Leader in Test Preparation ISBN: 978-1-4380-0594-2 ONLINE New chapter on the Computer STUDYGREEN Science A labs BARRON’S * BOOK BARRON’S with BARRON’S Teukolsky SCORE HIGHER Everything you need to get a 55 ONLINE *AP and Advanced Placement Program are registered trademarks of the College Board, which was not involved in the production of, and does not endorse, this product 11/7/14 12:41 PM Now Available! BARRON’S Online AP Exams Go to barronsbooks.com/AP/compsci/ to take a free sample AP Computer Science A test, complete with answer explanations and automated scoring *This online test was created for devices that support Adobe Flash Player To access the test on an Apple iPad or iPhone you will need to install a web browser that supports Flash (check the iTunes App Store for free options) 4-0594-AP-ComputerScienceA-IFC.indd All Pages 11/5/14 12:54 PM BARRON’S AP COMPUTER * SCIENCE A 7TH EDITION Roselyn Teukolsky, M.S Formerly, Ithaca High School Ithaca, New York *AP and Advanced Placement Program are registered trademarks of the College Board, which was not involved in the production of, and does not endorse, this book 4-0594-APComputerScienceA-tp.indd 10/7/14 9:09 AM ✐ ✐ “ap” — 2014/11/4 — 11:10 — page ii — #2 ✐ ✐ About the Author: Roselyn Teukolsky has an M.S degree from Cornell University, and has been teaching programming and computer science since 1980 She has published articles in The Mathematics Teacher and in the National Council of Teachers of Mathematics Yearbook She is the author of Barron’s ACT Math and Science Workbook and coauthor of Barron’s SAT 2400: Aiming for the Perfect Score She has received the Edyth May Sliffe Award for Distinguished Mathematics Teaching and the Alfred Kalfus Distinguished Coach Award from the New York State Math League (NYSML) c Copyright 2015, 2013, 2010 by Barron’s Educational Series, Inc Previous editions c copyright 2007 under the title AP Computer Science Levels A and AB, 2003 under the title How to Prepare for the AP Computer Science Advanced Placement Examination, JAVA Version, and 2001 under the title How to Prepare for the AP Computer Science Advanced Placement Examination by Barron’s Educational Series, Inc All rights reserved No part of this publication may be reproduced or distributed in any form or by any means without the written permission of the copyright owner All inquiries should be addressed to: Barron’s Educational Series, Inc 250 Wireless Boulevard Hauppauge, New York 11788 www.barronseduc.com ISBN: 978-1-4380-0594-2 ISBN (with CD-ROM): 978-1-4380-7553-2 ISSN (Print): 2169-5571 ISSN (Print with CD-ROM): 2169-558X PRINTED IN THE UNITED STATES OF AMERICA 987654321 ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page iii — #3 ✐ ✐ Contents Preface ix Introduction General Information About the Exam Hints for Taking the Exam The Multiple-Choice Section The Free-Response Section How to Use This Book Practice Exam One / Diagnostic Test Computer Science Section I Computer Science Section II Answer Key (Section I) Diagnostic Chart for Practice Exam Answers Explained Chapter Introductory Java Language Features Packages and Classes Javadoc Comments Types and Identifiers Identifiers Built-in Types Storage of Numbers Hexadecimal and Octal Numbers Final Variables Operators Arithmetic Operators Relational Operators Logical Operators Assignment Operators Increment and Decrement Operators Operator Precedence Input/Output Input Output Escape Sequences Control Structures Decision-Making Control Structures Iteration Errors and Exceptions Multiple-Choice Questions on Introductory Java Language Concepts Answer Key Answers Explained xi xi xii xii xii xiii 33 45 45 47 57 57 59 60 60 60 61 62 63 63 63 64 65 66 66 67 67 67 67 68 69 69 71 74 77 88 88 iii ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page iv — #4 ✐ ✐ iv Contents Chapter Classes and Objects Objects Classes Public, Private, and Static Methods Headers Types of Methods Method Overloading Scope The this Keyword References Reference vs Primitive Data Types The Null Reference Method Parameters Multiple-Choice Questions on Classes and Objects Answer Key Answers Explained 92 92 93 94 95 95 95 99 100 100 101 101 103 103 111 126 126 Chapter Inheritance and Polymorphism 131 Inheritance 131 Superclass and Subclass 131 Inheritance Hierarchy 131 Implementing Subclasses 132 Declaring Subclass Objects 137 Polymorphism 138 Dynamic Binding (Late Binding) 138 Using super in a Subclass 139 Type Compatibility 140 Downcasting 140 The ClassCastException 142 Abstract Classes 142 Abstract Class 142 The abstract Keyword 142 Interfaces 144 Interface 144 Defining an Interface 145 The implements Keyword 145 The Comparable Interface 145 Multiple-Choice Questions on Inheritance and Polymorphism 150 Answer Key 169 Answers Explained 169 Chapter Some Standard Classes The Object Class The Universal Superclass Methods in Object The String Class String Objects Constructing String Objects The Concatenation Operator 174 174 174 174 177 177 177 178 ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page v — #5 ✐ ✐ Contents v Comparison of String Objects Other String Methods Wrapper Classes The Integer Class The Double Class The Math Class Random Numbers Multiple-Choice Questions on Standard Classes Answer Key Answers Explained 178 179 180 181 182 183 184 187 200 200 Chapter Program Design and Analysis 207 The Software Development Life Cycle 207 The Waterfall Model 207 Program Specification 208 Program Design 208 Program Implementation 208 Testing and Debugging 208 Program Maintenance 210 Object-Oriented Program Design 210 Identifying Classes 210 Identifying Behaviors 211 Determining Relationships Between Classes 211 UML Diagrams 212 Implementing Classes 212 Implementing Methods 213 Vocabulary Summary 219 Program Analysis 219 Program Correctness 219 Assertions 219 Efficiency 220 Multiple-Choice Questions on Program Design and Analysis 221 Answer Key 230 Answers Explained 230 Chapter Arrays and Array Lists One-Dimensional Arrays Initialization Length of Array Traversing an Array Arrays as Parameters Array Variables in a Class Array of Class Objects Analyzing Array Algorithms Array Lists The Collections API The Collections Hierarchy Collections and Generics Auto-Boxing and -Unboxing The List Interface 233 233 233 234 235 235 238 239 240 241 241 242 242 242 243 ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page vi — #6 ✐ ✐ vi Contents The Methods of List The ArrayList Class Using ArrayList Collections and Iterators Definition of an Iterator The Iterator Interface Using a Generic Iterator Two-Dimensional Arrays Declarations Matrix as Array of Row Arrays Processing a Two-Dimensional Array Two-Dimensional Array as Parameter Multiple-Choice Questions on Arrays and Array Lists Answer Key Answers Explained Chapter Recursion Recursive Methods General Form of Simple Recursive Methods Writing Recursive Methods Analysis of Recursive Methods Sorting Algorithms That Use Recursion Recursive Helper Methods Recursion in Two-Dimensional Grids Sample Free-Response Question Sample Free-Response Question Multiple-Choice Questions on Recursion Answer Key Answers Explained 243 244 245 247 247 247 247 249 250 250 251 253 255 284 284 290 290 291 293 294 295 295 298 300 303 308 319 319 Chapter Sorting and Searching 324 Sorts: Selection and Insertion Sorts 324 Selection Sort 324 Insertion Sort 325 Recursive Sorts: Mergesort and Quicksort 325 Mergesort 325 Quicksort 327 Sorting Algorithms in Java 328 Sequential Search 329 Binary Search 329 Multiple-Choice Questions on Sorting and Searching 331 Answer Key 346 Answers Explained 346 Chapter The AP Computer Science A Labs The Magpie Lab Special Emphasis The Elevens Lab Special Emphasis 351 351 352 353 354 ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page vii — #7 ✐ ✐ Contents vii The Picture Lab Special Emphasis Multiple-Choice Questions on the Lab Concepts Answer Key Answers Explained Practice Exams Practice Exam Two Computer Science Section I Computer Science Section II Answer Key (Section I) Answers Explained Practice Exam Three Computer Science Section I Computer Science Section II Answer Key (Section I) Answers Explained 356 356 360 373 373 377 379 381 408 420 420 433 435 460 472 472 Appendix: Glossary of Useful Computer Terms 482 Index 485 ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page viii — #8 ✐ ✐ Barron’s Essential As you review the content in this book to work toward earning that on your AP Computer Science A exam, here are five things that you MUST know above everything else: The Basics Every AP exam question uses at least one of these: • • • Methods (p 95) Subclasses (p 131) Abstract classes (p 142) Interfaces (p 144) One-dimensional arrays (p 233) ArrayLists (p 244) Two-dimensional Arrays Learn to manipulate a matrix This topic has become more prominent on the AP exam in recent years • • • • Control structures (p 69) Lists and Arrays Learn to manipulate a list Search, delete an item, insert an item It seems as if every second question on the AP exam uses a list! • • Operators (p 63) Objects, Classes, and Inheritance You may have to write your own class You’ll definitely need to interpret at least one class that’s given • • • • Types and Identifiers (p 60) Two-dimensional arrays (p 249) Row-column traversal (p 251) for-each loop traversal (p 251) Row-by-row array processing (p 251) Sorting and Searching Know these algorithms! • • • • Selection Sort (p 324) Insertion Sort (p 325) Merge Sort (p 325) Binary Search (p 329) ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page 478 — #492 ✐ ✐ 478 Practice Exams Section II (a) public boolean isAisleSeat (int row, int seatNumber) { return seatNumber == || seatNumber == SEATS_PER_ROW - 1; } (b) public boolean twoTogether() { for (int r = 0; r < NUM_ROWS; r++) for (int c = 0; c < SEATS_PER_ROW-1; c++) if (seats[r][c] == && seats[r][c+1] == 0) { seats[r][c] = 1; seats[r][c+1] = 1; return true; } return false; } (c) public int findAdjacent(int row, int seatsNeeded) { int index = 0, count = 0, lowIndex = 0; while (index < SEATS_PER_ROW) { while (index < SEATS_PER_ROW && seats[row][index] == 0) { count++; index++; if (count == seatsNeeded) return lowIndex; } count = 0; index++; lowIndex = index; } return -1; } Practice Exam NOTE • In part (a), the seat numbers go from to SEATS_PER_ROW - • In part (b), you need the test c < SEATS_PER_ROW-1, because when you refer to seats[r][c+1], you must worry about going off the end of the row and causing an ArrayIndexOutOfBounds exception • In part (c), every time you increment index, you need to test that it is in range This is why you need this test twice: index < SEATS_PER_ROW • In part (c), every time you reset the count, you need to reset the lowIndex, because this is the value you’re asked to return • In parts (b) and (c), the final return statements are executed only if all rows in the show have been examined unsuccessfully ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page 479 — #493 ✐ ✐ Answers Explained 479 (a) public String replaceAll(String line, String sub, String repl) { int pos = line.indexOf(sub); while (pos >= 0) { line = line.substring(0, pos) + repl + line.substring(pos + sub.length()); pos = line.indexOf(sub); } return line; } (b) public void createPersonalizedLetters() { for (int i = 0; i < customers.size(); i++) { List tempLines = makeCopy(); Customer c = customers.get(i); for (int j = 0; j < tempLines.size(); j++) { tempLines.set(j, replaceAll(tempLines.get(j), "@", c.getName())); tempLines.set(j, replaceAll(tempLines.get(j), "&", c.getCity())); tempLines.set(j, replaceAll(tempLines.get(j), "$", c.getState())); } writeLetter(tempLines); } } NOTE • In part (a), each time you encounter sub in line, you simply create a new line that concatenates the “before” substring, the replacement, and the “after” substring This guarantees termination of the loop: Eventually sub won’t be found in line because all occurrences have been replaced, and line.indexOf(sub) will return -1 (sub not found in line) • In part (b), you need a nested loop: for each customer, loop through all the lines and the replacements • In part (b), one of the tricky lines of code is You need a fresh, unchanged copy of lines for each customer If, by mistake, you use the line List tempLines = lines; then tempLines and lines will be the same reference, so any changes to tempLines will also be made to lines, and the second (and all subsequent) customers won’t have a fresh copy of lines with the tokens Instead, lines will contain the first customer’s information Practice Exam List tempLines = makeCopy(); ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page 480 — #494 ✐ ✐ 480 Practice Exams public class Outfit implements ClothingItem { private Shoes shoes; private Pants pants; private Top top; public Outfit (Shoes aShoes, Pants aPants, Top aTop) { shoes = aShoes; pants = aPants; top = aTop; } public String getDescription() { return shoes.getDescription() + "/" + pants.getDescription() + "/" + top.getDescription() + " outfit"; } public double getPrice() { if (shoes.getPrice() + pants.getPrice() >= 100 ||shoes.getPrice() + top.getPrice() >= 100 ||top.getPrice() + pants.getPrice() >= 100) return 0.75 * (shoes.getPrice() + pants.getPrice() + top.getPrice()); else return 0.90 * (shoes.getPrice() + pants.getPrice() + top.getPrice()); } } NOTE • To access the price and descriptions of items that make up an outfit, your class needs to have variables of type Shoes, Pants, and Top (a) public void shuffle() Practice Exam { for (int k = tiles.size() - 1; k > 0; k ) { int randIndex = (int) (Math.random() * (k + 1)); Tile temp = tiles.get(k); tiles.set(k, tiles.get(randIndex)); tiles.set(randIndex, temp); } unusedSize = tiles.size(); } ✐ ✐ ✐ ✐ ✐ ✐ “ap” — 2014/11/4 — 11:10 — page 481 — #495 ✐ ✐ Answers Explained 481 (b) public void replaceTiles(TileSet t) { int numTiles = NUM_LETTERS - playerTiles.size(); if (numTiles

Ngày đăng: 01/11/2018, 21:59

TỪ KHÓA LIÊN QUAN

w