AP® Computer Science Overview of AP® Computer Science Instructor Contact Info for Mr. Tedesco Room 118 Phone: (215) 750-2800 X3603 Email: rtedesco@bensalemsd.org School Website: www.bensalemsd.org/tedesco Twitter: @mrtedesco Exam Date: Tuesday May 6, 2014 at 8:00 AM Class Sessions Our classes meet daily in a block format for 93 minutes in each session. Course Overview The purpose of this class is to introduce the student to the object-oriented programming paradigm using the Java language. This course teaches students to use the standard Java library classes from the AP® Java subset delineated in Appendices A and B of the AP Computer Science Course Description. Concepts such as classes, objects, inheritance, polymorphism, and code reusability are studied. Hands-on lab work helps solidify each concept. My goal for this AP Computer Science course is to challenge students to be active learners and critical thinkers. I believe in hands-on learning. During daily class lab time, I can easily look at each student's code, informally tracking his or her progress, and assisting accordingly. I can talk to students about their programs, and they can ask specific questions about problems they are having. Computer Facilities Our classroom is also our lab - we find this to be very conducive to student learning. We have our computers arranged in four rows. An interactive board is mounted at the front of the room. Additionally, there are several white boards and bulletin boards for instructional and student use and for the displaying of the students’ work. I believe in hands-on learning. This classroom is available for student use during class, as well as after school on at least two days each week. There is extensive use of the lab by the students throughout the course. Each topic requires hands-on-activities by the students. Computer Environment Our computers are running Microsoft Windows 7, the Eclipse IDE, along with the latest version of the Java Development Kit. Internet access, along with other programs, including Microsoft Office, notepad, and jGrasp are available for the students’ use. Overview of AP ® Computer Science Texts / Reference Materials Fundamentals of Java: AP Computer Science Essentials, 4th Edition by Kenneth A. Lambert and Martin Osborne ISBN: 978-0-538-74492-8 Course Technology Cengage Learning GridWorld Case Study. The College Board, 2006. Each student will work with the case study later in the course as part of their preparation for the AP Exam. Quick Reference Guide – AP Computer Science A Each student will be given a copy of the Quick Reference Guide – AP Computer Science A. They will be permitted and encouraged to use the guide in class and for any testing or assessment activity. Syllabus at a Glance Week Chapter Topic 1-2 Chapter 1: Background 1.1 History of Computers 1.2 Computer Hardware and Software 1.3 Binary Representation of Information and Computer Memory 1.4 Programming Languages 1.5 The Software Development Process 1.6 Basic Concepts of Object-Oriented Programming 3-4 5 Syllabus Chapter 2: First Java Programs 2.1 Why Java? 2.2 The Java Virtual Machine and Byte Code 2.3 Choosing a User Interface Style 2.4 Hello World 2.5 Edit, Compile, and Execute 2.6 Temperature Conversion 2.7 Graphics and GUIs: Windows and Panels Chapter 3: Syntax, Errors, and Debugging 3.1 Language Elements 3.2 Basic Java Syntax and Semantics 3.3 Terminal I/O for Different Data Types 3.4 Comments 3.5 Programming Errors 3.6 Debugging 3.7 Graphics and GUIs: Drawing Shapes and Text AP Computer Science 2 Overview of AP ® Computer Science 6-8 Chapter 4: Introduction to Control Statements 4.1 Additional Operators 4.2 Standard Classes and Methods 4.3 A Visit to the Farm 4.4 The If and If-Else Statements 4.5 The While Statement 4.6 The For Statement 4.7 Nested Control Statements and the Break Statement 4.8 Using Loops with Text Files 4.9 Errors in Loops 4.1 Graphics and GUIs: I/O Dialog Boxes and Loops Design, Testing, and Debugging Hints 9-11 Chapter 6: Introduction to Defining Classes 6.1 The Internal Structure of Classes and Objects 6.2 A Student Class 6.3 Editing, Compiling, and Testing the Student Class 6.4 The Structure and Behavior of Methods 6.5 Scope and Lifetime of Variables 6.6 Graphics and GUIs: Images, A Circle Class, and Mouse Events 12-14 Chapter 7: Control Statements Continued 7.1 Logical Operators 7.2 Testing If Statements 7.3 Nested If Statements 7.4 Logical Errors in Nested If Statements 7.5 Nested Loops 7.6 Testing Loops 7.7 Loop Verification 7.8 Advanced Operations on Strings 7.9 Graphics and GUIs: Timers and Animations Design, Testing, and Debugging Hints Syllabus AP Computer Science 3 Overview of AP ® Computer Science 15-17 Chapter 10: Introduction to Arrays 10.1 Conceptual Overview 10.2 Simple Array Manipulations 10.3 Looping Through Arrays 10.4 Declaring Arrays 10.5 Working with Arrays That Are Not Full 10.6 Parallel Arrays 10.7 Using the Enhanced For Loop 10.8 Arrays and Methods 10.9 Arrays of Objects 10.1 Graphics and GUIs: Changing The View of Student Test Scores Design, Testing, and Debugging Hints 18 Review Review Materials from first half of year 19-20 Chapter 11: Classes Continued 11.1 Class (Static) Variables and Methods 11.2 Turtle Graphics 11.3 Java Interfaces—The Client Perspective 11.4 Java Interfaces—The Implementation Perspective 11.5 Code Reuse through Inheritance 11.6 Working with Arrays of Objects 11.7 Inheritance and Abstract Classes Some Observations about Interfaces, Inheritance, and Relationships among 11.8 Classes 11.9 Acceptable Classes for Parameters and Return Values 11.1 Error Handling With Classes 21-22 Chapter 12: Arrays Continued 12.1 Searching 12.2 Sorting 12.3 Insertions and Removals 12.4 Two-Dimensional Arrays 12.5 Applications of Two-Dimensional Arrays 12.7 Graphics and GUIs: Menus Syllabus AP Computer Science 4 Overview of AP ® Computer Science 23-24 Chapter 13: Recursion, Complexity, and Searching and Sorting 13.1 Recursion 13.2 Complexity Analysis 13.3 Binary Search 13.4 Quicksort 13.5 Merge Sort 13.6 Graphics and GUIs: Drawing Recursive Patterns Design, Testing, and Debugging Hints 25-31 Review for AP Exam R.1 Comprehensive review of all material for the year GridWorld Part 1 class activity based on material in Part 1 of the R.2 GridWorld Case Study R.3 GridWorld Role Play GridWorld Project 1 Given work with bug variations based on Part 2 of R.4 GridWorld Case Study GridWorld Project 2: Design your own class based on material in Part R.5 3 of GridWorld Case Study GridWorld Project 3: Design your own critters based on material in R.6 Part 4 of GridWorld Case Study R.7 GridWorld Case Study - Practice and Review R.8 Practice AP-type exams R.9 Practice previously released AP exams After the AP Exam Chapter 5: Using Classes and Objects in Media Computing 5.1 Introduction to Digital Image Processing 5.2 The Images Package 5.3 Image-Processing Algorithms 5.4 Introduction to Digital Sound Processing 5.5 The Sounds Package Chapter 8: 8.1 8.2 8.3 8.4 8.5 8.6 Syllabus Improving the User Interface A Thermometer Class Repeating Sets of Inputs A Menu-Driven Conversion Program Formatted Output with Printf and Format Handling Number Format Exceptions During Input Graphics and GUIs AP Computer Science 5 Overview of AP ® Computer Science Chapter 9: 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 Introduction to HTML and Applets Hypertext, Hypermedia, and the World Wide Web Overview of the Hypertext Markup Language Simple Text Elements Character-Level Formatting Lists Linking To Other Documents Multimedia Tables Applets Chapter 14: Introduction to Collections 14.1 Overview of Collections 14.2 Java Collection Resources 14.3 Using Lists 14.4 Using Stacks 14.5 Using Queues 14.6 Using Sets 14.7 Using Maps 14.8 The Glue That Holds Collections Together Chapter 15: Multithreading, Networks, and Client/Server Programming 15.1 Threads and Processes 15.2 Networks, Clients, and Servers Chapter Objectives: At the conclusion of each chapter, I expect that each student will be able to: Chapter 1: Give a brief history of computers. Describe how hardware and software make up computer architecture. Explain the binary representation of data and programs in computers. Discuss the evolution of programming languages. Describe the software development process. Discuss the fundamental concepts of object-oriented programming Syllabus AP Computer Science 6 Overview of AP ® Computer Science Chapter 2: Discuss why Java is an important programming language. Explain the Java virtual machine and byte code. Choose a user interface style. Describe the structure of a simple Java program. Write a simple program. Edit, compile, and run a program using a Java development environment. Format a program to give a pleasing, consistent appearance. Understand compile-time errors. Write a simple graphics program. Chapter 3: Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different arithmetic operators. Concatenate two strings or a number and a string. Know how and when to use comments in a program. Tell the difference between syntax errors, run-time errors, and logic errors. Insert output statements to debug a program. Understand the difference between Cartesian coordinates and screen coordinates. Work with color and text properties. Chapter 4: Use the increment and decrement operators. Use standard math methods. Use if and if-else statements to make choices. Use while and for loops to repeat a process. Construct appropriate conditions for control statements using relational operators. Detect and correct common errors involving loops. Chapter 5: Use the concepts of object-based programming—classes, objects, and methods— to solve a problem. Write a loop to visit a sequence of data values. Write a nested loop to visit positions in a two-dimensional grid of data values. Develop algorithms to perform simple transformations of images, such as the conversion of color to gray scale. Develop algorithms to perform simple transformations of sound clips, such as adjusting a sound clip’s volume Syllabus AP Computer Science 7 Overview of AP ® Computer Science Chapter 6: Design and implement a simple class from user requirements. Organize a program in terms of a view class and a model class. Use visibility modifiers to make methods visible to clients and restrict access to data within a class. Write appropriate mutator methods, accessor methods, and constructors for a class. Understand how parameters transmit data to methods. Use instance variables, local variables, and parameters appropriately. Organize a complex task in terms of helper methods. Chapter 7: Construct complex Boolean expressions using the logical operators && (AND), || (OR), and ! (NOT). Construct truth tables for Boolean expressions. Understand the logic of nested if statements and extended if statements. Test if statements in a comprehensive manner. Construct nested loops. Create appropriate test cases for if statements and loops. Understand the purpose of assertions, invariants, and loop verification. Chapter 8: Construct a query-driven terminal interface. Construct a menu-driven terminal interface. Construct a graphical user interface. Format text, including numbers, for output. Handle number format exceptions during input. Chapter 9: Describe the basic features of hypertext, hypermedia, and the World Wide Web. Use basic HTML markup tags to format text for a Web page. Construct an HTML list and an HTML table to represent a linear sequence of items and a two-dimensional grid of items, respectively. Use the appropriate markup tags to include images in Web pages. Create links to other Web pages using absolute or relative path names. Convert a Java application to an applet and embed the applet in a Web page. List the constraints on applets that distinguish them from Java applications. Syllabus AP Computer Science 8 Overview of AP ® Computer Science Chapter 10: Write programs that handle collections of similar items. Declare array variables and instantiate array objects. Manipulate arrays with loops, including the enhanced for loop. Write methods to manipulate arrays. Create parallel arrays and two-dimensional arrays. Chapter 11: Explain when it is appropriate to include class (static) variables and methods in a class. Describe the role of Java interfaces in a software system and define an interface for a set of implementing classes. Explain the how to extend a class through inheritance. Discuss the use of polymorphism and explain how to override methods in a superclass. Place the common features (variables and methods) of a set of classes in an abstract class. Explain the implications of reference types for equality, copying, and mixedmode operations. Define and use methods that have preconditions, postconditions, and that throw exceptions. Chapter 12: Write a method for searching an array Write a method for sorting an array Write methods to perform insertions and removals at given positions in an array Create and manipulate two-dimensional arrays Chapter 13: Design and implement a recursive method to solve a problem. Understand the similarities and differences between recursive and iterative solutions of a problem. Check and test a recursive method for correctness. Understand how a computer executes a recursive method. Perform a simple complexity analysis of an algorithm using big-O notation. Recognize some typical orders of complexity. Understand the behavior of a complex sort algorithm such as the quicksort. Chapter 14: Recognize different categories of collections and the operations on them Distinguish between a collection’s interface and its implementing classes Use list, stack, queue, set, and map collections to solve problems Choose a particular collection implementation based on its performance characteristics. Syllabus AP Computer Science 9 Overview of AP ® Computer Science Chapter 15: Describe what threads do and explain the advantages of multithreading Explain how threads are manipulated in an application Code an algorithm to run as a thread Use conditions to solve a simple synchronization problem with threads Use IP addresses, ports, and sockets to create a simple client/server application on a network Decompose a server application with threads to handle client requests efficiently Restructure existing applications for deployment as client/server applications on a network. Teaching Strategies In each chapter, students obtain instruction and perform class activities, which will include programming assignments for hands-on practice. Each assignment is be reviewed and returned to the students so that they can make any program changes that are necessary to fulfill the assignment’s requirements. New vocabulary is be introduced in each chapter and student-centered activities will reinforce the vocabulary. Assessments In addition to the hands-on labs, the students have short quizzes, and a chapter test for each chapter. We also have quarterly assessments which will encompass the material for that quarter. Projects and Activities In each chapter, the students complete projects to demonstrate their understanding of the class material. These projects also help to prepare them for the analysis that is required for the AP Exam. Chapter 1: In Project 1-1, students will discuss the different components of the computer that they are using for this course, including software, hardware, memory, CPU requirements (speed, etc.), and the operating system. In the Critical Thinking Activity, students will discuss the ethical and legal issues surrounding copyrighting. Syllabus AP Computer Science 10 Overview of AP ® Computer Science Chapter 2: In Project 2-1, students will write a program that displays their name, address, and telephone number. In Project 2-3, students will write a program that takes as input a number of kilometers and prints the corresponding number of nautical miles. In Project 2-4, students will write a program that calculates and prints the number of minutes in a year. In Project 2-5, students will write a program that expects an object’s mass (in kilograms) and velocity (in meters per second) as inputs and prints its momentum. Chapter 3: In Project 3-1, students will write a program that takes the length of an edge (an integer) as input and prints the cube’s surface area as output. In Project 3-2, students will write a program that takes the radius of a sphere (a double) as input and outputs the sphere’s diameter, circumference, surface area, and volume. In Project 3-3, students will modify the program of Project 2-5 in Chapter 2 so that it prints the object’s kinetic energy as well as its momentum. In Project 3-4, students will write a program that takes as inputs the hourly wage, total regular hours, and total overtime hours and displays an employee’s total weekly pay. In Project 3-5, students will modify the program in Project 3-4, so that it prompts the user for the regular and overtime hours of each of five working days. Syllabus AP Computer Science 11 Overview of AP ® Computer Science Chapter 4: In Project 4-1, students will write a program that takes two integers as inputs and displays their quotient and remainder as outputs. In Project 4-2, students will write a program that takes the lengths of three sides of a triangle as inputs. The program should display whether or not the triangle is a right triangle. In Project 4-3, students will write a program that takes the total length of a call in minutes as input and calculates and displays the cost. In Project 4-4, students will run the Factorial program of Section 4.5 with inputs of 5, 10, and 20. The number for the last output is large but negative. They will place an output statement in the loop so that they can view the value of count and number on each pass. They will explain what the problem is and then change the type of product from int to long, recompile the program, and run it again with the same inputs. They will explain what happens, stating how large the input has to be before they encounter the same problem again. In Project 4-5, students will write a program that uses Leibniz’s method to compute the value of pi (∏), allows the user to specify the number of iterations used in this approximation, and displays the resulting value. In Project 4-6, students will write a program that allows a biologist to predict population growth. In Project 4-7, students will write a program that displays the positive powers of 2. In Project 4-8, students will modify the program of Project 4-7 so that the user can specify the base (2 or higher) as well. In Project 4-9, students will modify the program of Project 4-8 so that it processes a file of inputs. In Project 4-10, students will write a program that displays a salary schedule for teachers in a school district. Chapter 6: In Project 6-1, students will add the extra constructors to the Student class of this chapter’s Case Study (Student Test Scores) and test these methods thoroughly with a Tester program. In Project 6-2, students will implement and test a method to validate a student’s data in the Student class. In Project 6-3, students will develop a new class for representing fractions and doing arithmetic with them. In Project 6-4, students will redo the Lucky Sevens dice-playing program from Chapter 4 so that it uses dice objects. In Project 6-5, students will develop a new class for representing bank accounts. In Project 6-6, students will develop new classes for representing books and patrons in a library. In Project 6-8, students will define a Rectangle class to represent rectangles. In the Critical Thinking Activity, students will modify the Fraction class so that it displays fractions in a form that is reduced to lowest terms. Syllabus AP Computer Science 12 Overview of AP ® Computer Science Chapter 7: In Project 7-1, students will write a program that plays a guessing game. The user knows the number and the computer must guess it. In Project 7-2, students will rewrite the program of Project 7-1 so that the user knows the number and the computer must guess it. In Project 7-3, students will write a program that expects a numeric grade as input and outputs the corresponding letter grade. In Project 7-4, students will write a Java method getLetterGrade that is based on the grading scale of Project 7-3 and use this method in a program that inputs a list of grades (ending with -1) and outputs the class average, the class minimum, and the class maximum as letter grades. In Project 7-5, students will write a program that lets the user enter two integers and then prints each step in the process of using the Euclidean algorithm to find their GCD. In Project 7-6, students will review the case study in Chapter 4 in which the Lucky Sevens gambling game program was created. They will remove the code that deals with the maximum amount held. They will then modify the program so that it runs the simulation 100 times and prints the average number of rolls. In Project 7-7, students will write a program to print the perimeter and area of rectangles using all combinations of heights and widths running from 1 foot to 10 feet in increments of 1 foot. They will print the output in headed, formatted columns. In Project 7-8, students will write a program to use a scanner to report statistics about words in an input sentence. The outputs should include the number of words in the sentence, the average word length, and the length of the sentence. In Project 7-9, students will write a program that allows users to search for a given word in a text file using the file’s name and target words as the inputs. In the Critical Thinking Activity, students will read the sections of the ACM Code of Ethics that deal with designing and testing reliable computer systems. They will prepare a written report to present to your class on the way in which the ACM Code deals with this issue. Syllabus AP Computer Science 13 Overview of AP ® Computer Science Chapter 10: In Project 10-1, students will write a program that takes 10 integers as input. The program places the even integers into an array called evenList, the odd integers into an array called oddList, and the negative integers into an array called negativeList. The program displays the contents of the three arrays after all of the integers have been entered. In Project 10-2, students will write a program that takes 10 floating-point numbers as inputs. The program displays the average of the numbers followed by all of the numbers that are greater than the average. In Project 10-3, students will write a program that takes 10 numbers as input and displays the mode of these numbers. In Project 10-4, students will add to the program of Project 10-3 the capability of displaying the median of the list of numbers. In Project 10-5, students will modify the program of Project 10-4 so that it displays not only the median and mode of the list of numbers, but also a table of the numbers and their associated frequencies. In Project 10-6, students will complete the student test scores application from this chapter’s Case Study and test it thoroughly. In the Critical Thinking Activity, students will write an algorithm for searching in an array. Chapter 11: In Project 11-1, students will design a hierarchy of classes that models the classification of their favorite region of the animal kingdom. In Project 11-2, students will design a hierarchy of classes that represents the classification of artifacts, such as vehicles. In Project 11-3, students will add a method perimeter to the Shape hierarchy from this chapter. This method should return the circumference of a circle and a wheel and the perimeter of a rectangle. In Project 11-4, students will add a Triangle class to the Shape hierarchy from this chapter. In Project 11-5, students will design a class hierarchy for bank accounts. The concrete types of accounts are checking accounts, savings accounts, and credit accounts. In Project 11-6, students will browse Java’s class hierarchy on Sun’s Web site and write an essay that describes the design ideas underlying a class hierarchy that they find interesting among Java’s classes. In the Critical Thinking Activity, students will defend the virtues of abstract classes. Syllabus AP Computer Science 14 Overview of AP ® Computer Science Chapter 12: In Project 12-1, students will define a class named ArrayList that supports random access to a list of objects via a numeric position. In Project 12-2, students will add the methods size and get to the program from Project 12-1. In Project 12-3, students will add the methods add and remove to the program from Project 12-2. In Project 12-4, students will complete the tic-tac-toe example by adding a method that tests for the winner. In Project 12-5, students will modify the program in Project 12-4 so that the computer is the second player. In Project 12-6, students will modify the program in Project 12-5 so that the computer tries to win. In Project 12-7, students will complete the golf program example finishing the methods. In Project 12-8, students will add a method to the golf program called getHandicap. In Project 12-9, students will add a new method, rule2, to the Sudoku program for the case study that runs if the rule1 method doesn’t eliminate all of the zeroes. In Project 12-10, students will add a new method, rule3, to the Sudoku program for the case study that runs if the rule1 and rule 2 methods don’t eliminate all of the zeroes. In Project 12-11, students will write a program that determines whether a square is a magic square. In Project 12-12, students will write a program that takes input and displays Pascal’s triangle. In Project 12-13, students will write a program that plays the penny pitch game. In Project 12-14, students will complete the GUI program from Section 12-8. In the Critical Thinking Activity, students will suggest a method for loading numbers from a text file into an array. Syllabus AP Computer Science 15 Overview of AP ® Computer Science Chapter 13: In Project 13-1, students will use a Tester program to implement and test a recursive method to compute the greatest common divisor (gcd) of two integers. In Project 13-2, students will write a recursive method that returns a string with the characters in reverse order and test the method with a Tester program. In Project 13-3, students will design, implement, and test a recursive method that expects a positive integer parameter and returns a string representing that integer with commas in the appropriate places. In Project 13-4, students will write a program that takes the values of n and k as inputs and displays as output the value n choose k. In Project 13-5, students will modify the Case Study of this chapter so that it counts comparison and exchange operations in both sort algorithms and displays these statistics as well. In Project 13-6, students will write a Tester program to help assess the efficiency of the Towers of Hanoi program. In Project 13-7, students will write a Tester program to help assess the efficiency of the Many Queens program. In the Critical Thinking Activity, students will explain the tradeoffs between the use of iterative algorithms and recursive algorithms. Syllabus AP Computer Science 16 Overview of AP ® Computer Science After the Exam: Chapter 5: In Project 5-1, students will write an algorithm that converts an image to two random colors (instead of black and white), and another that asks for an image filename for the colored image. In Project 5-2, students will write an algorithm that converts a color image to grayscale, weighting the RGB values to more accurately reflect how images are viewed by the human eye. In Project 5-3, students will write a program that inverts a grayscale image so that it looks like a photographic negative. In Project 5-4, students will write a program that converts an image to sepia. In Project 5-5, students will write a program that applies a color filter to an image. In Project 5-6, students will write a program that detects edges, and brightens or darkens the pixels to enhance the outlines of objects. In Project 5-7, students will write a program that blurs an entire image. In Project 5-8, students will write a program that reduces the size of an image by a given factor. In Project 5-9, students will write a program that enlarges an image. In Project 5-10, students will write a program that rotates an image counterclockwise by 90 degrees. In Project 5-11, students will modify the sample program that adjusts the volume of a sound clip so that it avoids exceeding the limits on the size of a sample. In Project 5-12, students will write a program that splices two sound clips. In Project 5-13, students will write a program that composes two sound clips. In Project 5-14, students will write a program that introduces echo into a sound clip. In Project 5-15, students will write a program that accepts the name of a sound clip as input and creates a new file that is the inverse of the clip. In the Critical Thinking Activity, students will evaluate a suggestion that a more accurate black-and-white image can be created by first converting the image to grayscale, then converting the grayscale image to black and white. Syllabus AP Computer Science 17 Overview of AP ® Computer Science Chapter 8: In Project 8-1, students will write a query-driven program that allows the user to enter a number and the number of approximations to compute its square root using Newton’s method. In Project 8-2, students will modify the program of Project 8-1 so that the user can view the successive approximations. In Project 8-3, students will write a program that calculates how much money will be in a mutual fund after 20 years. In Project 8-4, students will write a program that takes a purchase price as input. The program should display a table of the payment schedule for the lifetime of a simple interest loan for the purchase. In Project 8-5, students will modify the final temperature conversion program of Section 8.6 so that it displays the results of each conversion rounded to the nearest hundredth of a degree. In the Critical Thinking Activity, students will discuss the issues involved in choosing between terminal-based and GUI-based interfaces from a client’s perspective. Chapter 9: In Project 9-1, students will create a home page on a local Web server. They should include a title, a brief paragraph that states who they are, and a picture of their favorite pastime. In Project 9-2, students will add a list of courses they are currently taking to their Web site. In Project 9-3, students will make each item in the list from Project 9-2 link to a page that describes that item. In Project 9-4, students will add links to each of the pages created in Project 9-3 that return the user to their home pages. In Project 9-5, students will write an applet that plays the game of guess-thenumber with the user and then add it to their Web site. In the Critical Thinking Activity, students will write a short essay that compares the advantages and disadvantages of using Java applications and applets. Syllabus AP Computer Science 18 Overview of AP ® Computer Science Grading Policy In accordance with Bensalem HS Unified Grading Policy, the students’ grades will be calculated as follows: 30% Major Tests and/or Projects o Minimum of 3 per marking period 30% Minor Tests and/or Projects o Minimum of 6 per marking period 20% Classwork Cooperation 10% Quarterly Common Assessments o District Mandated Quarterly Assessments 10% Homework Syllabus AP Computer Science 19 Overview of AP ® Computer Science Java Subset Cross-Referenced to Text Language Features 1. The primitive types int, double, and boolean are part of the AP Java subset. The other primitive types short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are composed of char values. Introducing char does not increase the expressiveness of the subset. Students already need to understand string concatenation, String.substring,and String.equals. Not introducing char avoids complexities with the char/int conversions and confusion between "x" and 'x'. (Chapter 3.2 Page 59) 2. Arithmetic operators: +, -, *, /, % are part of the AP Java subset. (Chapter 3.1 Page 58) 3. The increment/decrement operators ++ and -- are part of the AP Java subset. These operators are used only for their side effect, not for their value. That is, the postfix form (for example, x++) is always used, and the operators are not used inside other expressions. For example, a[x++] is not used. (Chapter 4.1 Page 106) 4. The assignment operator = is part of the AP Java subset. The combined arithmetic/assignment operators +=, -=, *=, /=, %= are part of the AP Java subset although they are used simply as a shorthand and will not be used in the adjustment part of a for loop. (Chapter 2.6 Page 44) 5. Relational operators ==, !=, <, <=, >, >= are part of the AP Java subset. (Chapter 4.4 Page 114) 6. Logical operations &&, ||, ! are part of the AP Java subset. Students need to understand the "short circuit" evaluation of the && and || operators. The logical&, | and ^ and the bit operators <<, >>, >>>, &, ~, |, ^ are not in the subset. (Chapter 7.1 Page 232) 7. The ternary ?: operator is not in the subset. N/A BUT DISCUSS IN CLASS 8. The numeric casts (int) and (double) are part of the AP Java subset. Since the only primitive types in the subset are int, double, and boolean, the only required numeric casts are the cast (int) and the cast (double). Students are expected to understand "truncation towards 0" behavior as well as the fact that positive floating-point numbers can be rounded to the nearest integer as (int)(x + 0.5), negative numbers as (int)(x - 0.5). Autoboxing, that is the automatic conversion between primitive types (int, double) and the corresponding wrapper classes (Integer, Double) is not in the subset. (Chapter 3.2 Page 67) Syllabus AP Computer Science 20 Overview of AP ® Computer Science 9. String concatenation + is part of the AP Java subset. Students are expected to know that concatenation converts numbers to strings and invokes toString on objects. String concatenation can be less efficient than using the StringBufferclass. However, for greater simplicity and conceptual clarity, the StringBufferclass is not in the subset. (Chapter 3.2 Page 68) 10. The escape sequences inside strings \\, \", \n are part of the AP Java subset. The \t escape and Unicode \uxxxx escapes are not in the subset. The\' escape is only necessary inside character literals and is not in the subset. (Chapter 3.2 Page 69) 11. User input is not part of the AP Java subset. There are many possible ways for supplying user input; e.g., by reading from a BufferedReader that is wrapped around System.in, reading from a stream (such as a file or an URL), or from a dialog box. There are advantages and disadvantages to the various approaches. In particular, reading from System.in is both fraught with complexities (two nested readers and the handling of checked exceptions) and considered old fashioned by some instructors. The exam does not prescribe any one approach. Instead, if reading input is necessary, it will be indicated in a way similar to the following: double x = call to a method that reads a floating-point number; or double x = IO.readDouble(); // read user input Converting strings to numeric values (e.g., with Integer.parseInt) is not in the subset. N/A – BUT DISCUSS IN CLASS 12. Testing of output is restricted to System.out.print and System.out.println. As with user input, there are many possible ways for directing the output of a program, for example to System.out, to a file, or to a text area in a graphical user interface. The AP Java subset includes the ability to print output to System.out, because it makes it easy to formulate questions. Since most graphical environments allow printing of debug messages to System.out (with output being collected in a special window, e.g., the "Java console" in a browser), students are usually familiar with this method of producing output. Formatted output (e.g., with NumberFormat or System.out.printf) is not in the subset. (Chapter 2.4 Page 35) Syllabus AP Computer Science 21 Overview of AP ® Computer Science 13. The main method and command-line arguments are not in the subset. The AP Computer Science Committee does not prescribe any particular approach for program invocation. In free-response questions, students are not expected to invoke programs. In case studies, program invocation with main may occur, but the main method will be kept very simple. N/A BUT DISCUSS IN CLASS 14. Arrays: one-dimensional arrays and two-dimensional rectangular arrays are part of the AP Java subset. Both arrays of primitive types (e.g., int[]) and arrays of objects (e.g., Student[] ) are in the subset. Initialization of named arrays (int[] arr = { 1, 2, 3 };) is part of the AP Java subset. Arrays with more than two dimensions (e.g., rubik = new Color[3][3][3]) are not in the subset. "Ragged" arrays (e.g., new int[3][]) are not in the subset. In particular, students do not need to know that an int[3][3] really is an "array of arrays" whose rows can be replaced with other int[] arrays. However, students are expected to know that arr[0].length is the number of columns in a rectangular two-dimensional array arr. Anonymous arrays (e.g., new int[] { 1, 2, 3 }) are not in the subset. (1-dimensional: Chapter 10.1 Page 342; 2-dimensional: Chapter 12.4 Page 456) 15. The control structures if, if/else, while, for, (including the enhanced for loop), return are part of the AP Java subset. The do/while, switch, plain and labeled break and continue statements are not in the subset. (if-else: Chapter 4.4 Page 111 ; while: (Chapter 4.5 Page 116; for: Chapter 4.6 Page 120) 16. Methods: Method overloading (e.g., MyClass.method(String str) andMyClass.method(int num)) is part of the AP Java subset. Students should understand that the signature of a method depends only on the number, types, and order of its parameters but does not include the return type of the method. (Chapter 3.2 Page 71) Methods with a variable number of parameters are not in the subset. (Chapter 1.6 Page 24 and overloading: Chapter 4.2 Page 107) 17. Classes: Students are expected to construct objects with the new operator, to supply construction parameters, and to invoke accessor and modifier methods. Students are expected to modify existing classes (by adding or modifying methods and instance variables). Students are expected to design their own classes. (Constructor: Chapter 6.1 Page 125; Accessor / Modifier: Chapter 5.1 Page 156; Classes: Chapter 6.1 Page 125) 18. Visibility: In the AP Java subset, all classes are public. All instance variables are private. Methods, constructors, and constants (static final variables) are either public, or private. (Chapter 3.2 Page 62) The AP Java subset does not use protected and package (default) visibility. N/A Syllabus AP Computer Science 22 Overview of AP ® Computer Science 19. The AP Java subset uses /* */, // and /** */ comments. Javadoc comments@param and @return, are part of the subset. (/* */: Chapter 3.4 Page 77-78; //: Chapter 11.10 Page 422-426; /** */: Chapter 11.10 Page 422-426; Javadoc Chapter 11.10 Page 422-426; plus teacher handout) 20. The final keyword is only used for final block scope constants and static final class scope constants, final parameters or instance variables, final methods and final classes are not in the subset. (Chapter 3.2 Page 62) 21. The concept of static methods is a part of the subset. Students are required to understand when the use of static methods is appropriate. In the exam, static methods are always invoked through a class, never an object (i.e., ClassName.method(), not obj.method()). (Chapter 11.1 Page 387) 22. static variables are part of the subset. (Chapter 11.1 Page 387) 23. The null reference is part of the AP Java subset. (Chapter 6.2 Page 190) 24. The use of this is restricted to passing the implicit parameter in its entirety to another method (e.g., obj.method(this)) and to descriptions such as "the implicit parameter this". (Teacher created materials) Using this.var or this.method(args) is not in the subset. N/A In particular, students are not required to know the idiom "this.var = var", where var is both the name of an instance variable and a parameter variable. N/A Calling other constructors from a constructor with the this(args)notation is not in the subset. N/A 25. The use of super to invoke a superclass constructor (super(args)) or to invoke a superclass method (i.e., super.method(args)) is part of the AP Java subset. (Chapter 11.5 Page 402) 26. Students are expected to implement constructors that initialize all instance variables. Class constants are initialized with an initializer: public static final int MAX_SCORE = 5; The rules for default initialization (with 0, false or null) are not in the subset. Initializing instance variables with an initializer is not in the subset. Initialization blocks are not in the subset. (Chapter 6.5 Page 210-212) 27. Students are expected to extend classes and implement interfaces. Students are also expected to have a knowledge of inheritance that includes understanding the concepts of method overriding and polymorphism. Students are expected to implement their own subclasses. (Chapter 11.4 Page 394 – 403) Syllabus AP Computer Science 23 Overview of AP ® Computer Science 28. Students are expected to read the definitions of interfaces and abstract classes and understand that the abstract methods need to be implemented in a subclass. Students are expected to write interfaces or class declarations when given a general description of the interface or class. (Chapter 11.7 Page 406-411) 29. Students are expected to understand the difference between object equality (equals) and identity (==). The implementation of equals and hashCodemethods is not in the subset. (Identity: Chapter 4.3 Page 114; equality: Chapter2.6 Page 44) 30. Cloning is not in the subset, because of the complexities of implementing the clone method correctly and the fact that clone is rarely required in Java programs. N/A 31. The finalize method is not in the subset. N/A BUT DISCUSS IN CLASS 32. Students are expected to understand that conversion from a subclass reference to a superclass reference is legal and does not require a cast. Class casts (generally from Object to another class) are part of the AP Java subset, to enable the use of generic collections,(Chapter 11.6 Page 404-405) for example: Person p = (Person)people.get(i); The instance of operator is not in the subset. Array type compatibility and casts between array types are not in the subset. N/A BUT DISCUSS IN CLASS ` 33. Students are expected to have a basic understanding of packages and a reading knowledge of import statements of the form import packageName.subpackageName.ClassName; import statements with a trailing *, packages and methods for locating class files (e.g., through a class path) are not in the subset. (Chapter 3.2 Page 73) 34. Nested and inner classes are not in the subset. N/A BUT DISCUSS IN CLASS 35. The use of generic collection classes and interfaces are in the subset, but students need not implement generic classes or methods. ** KNOW HOW TO READ ** (Chapter 14.8 Page 575-577) 36. Enumerations, annotations, and threads are not in the subset. N/A BUT DISCUSS IN CLASS Syllabus AP Computer Science 24 Overview of AP ® Computer Science 37. Students are expected to understand the exceptions that occur when their programs contain errors (in particular, NullPointerException, ArrayIndexOutOfBoundsException, ArithmeticException, ClassCastException, IllegalArgumentException). On the AB exam, students are expected to be able to throw the uncheckedIllegalStateException and NoSuchElementException in their own methods (principally when implementing collection ADTs). Checked exceptions are not in the subset. In particular, the try/catch/finally statements and the throwsmodifier are not in the subset. (Chapter 3.5 Pages 82-86; teacher created handout) Syllabus AP Computer Science 25 Overview of AP ® Computer Science Appendix A — Java Quick ReferenceStandard Java Library Accessible Methods from the Java Library That May Be Included on the Exam class java.lang.Object boolean equals(Object other) String toString() class java.lang.Integer Integer(int value) int intValue() Integer.MIN_VALUE // minimum value represented by an int Integer.MAX_VALUE // maximum value represented by an int class java.lang.Double Double(double value) double doubleValue() class java.lang.String int length() String substring(int from, int to) // returns the substring beginning at from // and ending at to-1 String substring(int from) // returns substring(from, length()) int indexOf(String str) // returns the index of the first occurrence of str; // returns -1 if not found Syllabus AP Computer Science 26 Overview of AP ® Computer Science int compareTo(String other) // returns a value < 0 if this is less than other // return a value = 0 if this is equal to other // return a value > 0 if this is greater than other class java.lang.Math static int abs(int x) static double abs(double x) static double pow(double base, double exponent) static double sqrt(double x) static double random() // returns a double in the range [0.0, 1.0) class java.util.List<E> int size() boolean add(E obj) // appends obj to the end of list; returns true void add(int index, E obj) // inserts obj at position index (0<= index <= size), // moving elements at position index and higher // to the right (adds 1 to their indices) and adjusts size E get(int index) E set(int index, E obj) // replaces the element at position index, with obj //returns the element formerly at the specified position E remove(int index) // removes element from position index, moving elements // at position index + 1 and higher to the left // (subtracts 1 from their indices) and adjusts size // returns the element formerly at the specified position class java.util.ArrayList List<E> implements java.util.List List<E> Syllabus AP Computer Science 27 Overview of AP ® Computer Science Appendix B — Testable API info.gridworld.grid.Location class (implements Comparable) public Location(int r, int c) constructs a location with given row and column coordinates public int getRow() returns the row of this location public int getCol() returns the column of this location public Location getAdjacentLocation(int direction) returns the adjacent location in the direction that is closest to direction public int getDirectionToward(Location target) returns the closest compass direction from this location toward target public boolean equals(Object other) returns true if other is a Location with the same row and column as this location; false otherwise public int hashCode() returns a hash code for this location Syllabus AP Computer Science 28 Overview of AP ® Computer Science public int compareTo(Object other) returns a negative integer if this location is less than other, zero if the two locations are equal, or a positive integer if this location is greater than other. Locations are ordered in row-major order. Precondition: other is a Location object. public String toString() returns a string with the row and column of this location, in the format (row, col) Compass directions: public static final int NORTH = 0; public static final int EAST = 90; public static final int SOUTH = 180; public static final int WEST = 270; public static final int NORTHEAST = 45; public static final int SOUTHEAST = 135; public static final int SOUTHWEST = 225; public static final int NORTHWEST = 315; Syllabus AP Computer Science 29 Overview of AP ® Computer Science Turn angles: public static final int LEFT = -90; public static final int RIGHT = 90; public static final int HALF_LEFT = -45; public static final int HALF_RIGHT = 45; public static final int FULL_CIRCLE = 360; public static final int HALF_CIRCLE = 180; public static final int AHEAD = 0; info.gridworld.grid.Grid<E> interface int getNumRows() returns the number of rows, or -1 if this grid is unbounded int getNumCols() returns the number of columns, or -1 if this grid is unbounded boolean isValid(Location loc) returns true if loc is valid in this grid, false otherwise Precondition: loc is not null Syllabus AP Computer Science 30 Overview of AP ® Computer Science E put(Location loc, E obj) puts obj at location loc in this grid and returns the object previously at that location (or null if the location was previously unoccupied). Precondition: (1) loc is valid in this grid (2) obj is not null E remove(Location loc) removes the object at location loc from this grid and returns the object that was removed (or null if the location is unoccupied) Precondition: loc is valid in this grid E get(Location loc) returns the object at location loc (or null if the location is unoccupied) Precondition: loc is valid in this grid ArrayList<Location> getOccupiedLocations() returns an array list of all occupied locations in this grid ArrayList<Location> getValidAdjacentLocations(Location loc) returns an array list of the valid locations adjacent to loc in this grid Precondition: loc is valid in this grid ArrayList<Location> getEmptyAdjacentLocations(Location loc) returns an array list of the valid empty locations adjacent to loc in this grid Precondition: loc is valid in this grid Syllabus AP Computer Science 31 Overview of AP ® Computer Science ArrayList<Location> getOccupiedAdjacentLocations(Location loc) returns an array list of the valid occupied locations adjacent to loc in this grid Precondition: loc is valid in this grid ArrayList<E> getNeighbors(Location loc) returns an array list of the objects in the occupied locations adjacent to loc in this grid Precondition: loc is valid in this grid info.gridworld.actor.Actor class public Actor() constructs a blue actor that is facing north public Color getColor() returns the color of this actor public void setColor(Color newColor) sets the color of this actor to newColor public int getDirection() returns the direction of this actor, an angle between 0 and 359 degrees Syllabus AP Computer Science 32 Overview of AP ® Computer Science public void setDirection(int newDirection) sets the direction of this actor to the angle between 0 and 359 degrees that is equivalent to newDirection public Grid<Actor> getGrid() returns the grid of this actor, or null if this actor is not contained in a grid public Location getLocation() returns the location of this actor, or null if this actor is not contained in a grid public void putSelfInGrid(Grid<Actor> gr, Location loc) puts this actor into location loc of grid gr. If there is another actor at loc, it is removed. Precondition: (1) This actor is not contained in a grid. (2) loc is valid in gr. public void removeSelfFromGrid() removes this actor from its grid Precondition: this actor is contained in a grid public void moveTo(Location newLocation) moves this actor to newLocation. If there is another actor at newLocation, it is removed. Precondition: (1) This actor is contained in a grid. (2) newLocation is valid in the grid of this actor. Syllabus AP Computer Science 33 Overview of AP ® Computer Science public void act() reverses the direction of this actor. Override this method in subclasses of Actor to define types of actors with different behavior. public String toString() returns a string with the location, direction, and color of this actor info.gridworld.actor.Rock class (extends Actor) public Rock() constructs a black rock public Rock(Color rockColor) constructs a rock with color rockColor public void act() overrides the act method in the Actor class to do nothing info.gridworld.actor.Flower class (extends Actor) public Flower() constructs a pink flower Syllabus AP Computer Science 34 Overview of AP ® Computer Science public Flower(Color initialColor) constructs a flower with color initialColor public void act() causes the color of this flower to darken Syllabus AP Computer Science 35