© A+ Computer Science - www.apluscompsci.com Visit us at www.apluscompsci.com Full Curriculum Solutions www.apluscompsci.com M/C Review Question Banks.

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

© A+ Computer Science - GridWorld © A+ Computer Science -
Big Ideas behind Inheritance. Can you think of some possible examples of inheritance hierarchies?
Written by: Dr. JJ Shepherd
How to do well on the AP CS Free Response Questions
CIT 590 Intro to Programming Java lecture 4. Agenda Types Collections – Arrays, ArrayLists, HashMaps Variable scoping Access modifiers – public, private,
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
AP Computer Science.  Not necessary but good programming practice in Java  When you override a super class method notation.
© A+ Computer Science - ArrayList © A+ Computer Science - Lab 16.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 10 Using arrays to create collections.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java Unit 9: Arrays Declaring and Processing Arrays.
One Dimensional Arrays. Declaring references to array objects How would you declare a variable somearray that is an array of ints? int[] somearray;
Multiple Choice Solutions True/False a c b e d   T F.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
© A+ Computer Science - Inheritance © A+ Computer Science - Lab 20.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
ArrayList, Multidimensional Arrays
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
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.
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
How to do well on the AP CS Free Response Questions
1 Abstract Classes “I prefer Agassiz in the abstract, rather than in the concrete.” CS Computer Science II.
CS 206 Introduction to Computer Science II 02 / 13 / 2009 Instructor: Michael Eckmann.
© A+ Computer Science - Which of the following statements assigns the letter S to the third row and first column of a two-dimensional.
© A+ Computer Science - Grid is an interface that details the behaviors expected of a grid. All its methods are abstract methods.
Aug 9, CMSC 202 ArrayList. Aug 9, What’s an Array List ArrayList is  a class in the standard Java libraries that can hold any type of object.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
The GridWorld Case Study Program Section 1 - Overview of the Class Hierarchies Section 2 - The Actor Class Section 3 - The Rock and Flower Classes Section.
Arrays and ArrayLists Topic 6. One Dimensional Arrays Homogeneous – all of the same type Contiguous – all elements are stored sequentially in memory For.
CSE 1201 Object Oriented Programming ArrayList 1.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
CS1101 Group1 Discussion 6 Lek Hsiang Hui comp.nus.edu.sg
© A+ Computer Science - Visit my site at Full Curriculum Solutions M/C Review Question Banks Live Programming.
How to do well on the AP CS Free Response Questions
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Chapter 9 Introduction to Arrays Fundamentals of Java.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
1 Stacks Abstract Data Types (ADTs) Stacks Application to the analysis of a time series Java implementation of a stack Interfaces and exceptions.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
1 Topic 5 Polymorphism "“Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.”
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Elevens is a lab about classes and Lists. List is a major concept being tested by the Elevens lab. Elevens.
An Array-Based Implementation of the ADT List
Lecture 18: Nested Loops and Two-Dimensional Arrays
Objects as a programming concept
Topic Dimensional Arrays
A+ Computer Science AP Review 2018 AP CS A EXAM
Multiple Choice -answer the easiest question 1st
Writing Methods AP Computer Science A.
© A+ Computer Science - GridWorld © A+ Computer Science -
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
The Matrix A b a d e a a a a a a a A b a d e a a a a a a a
Topic 5 Polymorphism "“Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.”
Lecture 13: Two-Dimensional Arrays
© A+ Computer Science - GridWorld The GridWorld case study provides a graphical environment where visual objects inhabit and interact.
Review of Previous Lesson
Objects with ArrayLists as Attributes
A+ Computer Science AP Review 2019 AP CS A EXAM
A type is a collection of values
Presentation transcript:

© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content!

© A+ Computer Science - -Read all 4 questions before writing anything -answer the easiest question 1 st -most times question 1 is the easiest -see if part B calls part A and so on -many times part C consists of A and B calls -write something on every question -write legibly / use PENCIL!!!!!!!!!! -keep track of your time

© A+ Computer Science - -When writing methods -use parameter types and names as provided -do not redefine the parameters listed -do not redefine the methods provided -return from all return methods -return correct data type from return methods

© A+ Computer Science - -When writing a class or methods for a class -know which methods you have -know which instance variables you have -check for public/private on methods/variables -return from all return methods -return correct data type from return methods

© A+ Computer Science - -When extending a class -know which methods the parent contains -have the original class where you can see it -make sure you have super calls -check for public/private on methods/variables -make super calls in sub class methods as needed

© A+ Computer Science - -When extending abstract / implementing interface -know which methods the parent contains -have the original class where you can see it -make sure you have super calls -check for public/private on methods/variables -make super calls in sub class methods as needed -implement all abstract methods in sub class

© A+ Computer Science - ArrayList of References / Strings – get,set,remove,add,size – levels of abstraction GridWorld or Make a Class – location, actor, bug, critter, ROCK, grid, super, abstract Matrix / 2 D Array – nested loops, GridWorld ( grid ) Make a Class / Interfaces / Abstract – implement / extend – not seen this ? type in a few years

© A+ Computer Science - A typical ArrayList question involves putting something into an ArrayList and removing something from an ArrayList.

© A+ Computer Science - Arraylist is a class that houses an array. An ArrayList can store any type. All ArrayLists store the first reference at spot / index position 0.

© A+ Computer Science nums int[] nums = new int[10]; //Java int array An array is a group of items all of the same type which are accessed through a single identifier.

© A+ Computer Science - ArrayList frequently used methods NameUse add(item)adds item to the end of the list add(spot,item)adds item at spot – shifts items up-> set(spot,item)put item at spot z[spot]=item get(spot)returns the item at spot return z[spot] size()returns the # of items in the list remove()removes an item from the list clear()removes all items from the list import java.util.ArrayList;

© A+ Computer Science - List ray; ray = new ArrayList (); ray.add("hello"); ray.add("whoot"); ray.add("contests"); out.println(ray.get(0).charAt(0)); out.println(ray.get(2).charAt(0)); ray stores String references. OUTPUT h c

© A+ Computer Science - int spot=list.size()-1; while(spot>=0) { if(list.get(spot).equals("killIt")) list.remove(spot); spot--; }

© A+ Computer Science - for(int spot=list.size()-1; i>=0; i--) { if(list.get(spot).equals("killIt")) list.remove(spot); }

© A+ Computer Science - int spot=0; while(spot<list.size()) { if(list.get(spot).equals("killIt")) list.remove(spot); else spot++; }

© A+ Computer Science - public String scrambleWord( String word ) { String ret = ""; for( int i = 0; i < word.length(); i++ ) { if( i+1 != word.length() && word.substring(i,i+1).equals("A") && !word.substring(i+1,i+2).equals("A")) { ret += word.substring(i+1,i+2) + word.substring(i,i+1); i++; //prevents hitting the same “A” again } else { ret += word.substring(i,i+1); } return ret; } You must know String!

© A+ Computer Science - public void scrambleOrRemove( List wordList ) { for( int i = wordList.size()-1; i >= 0; i--) { String cur = wordList.get( i ); String ret = scrambleWord( cur ); if( ret.equals( cur ) ) wordList.remove( i ); else wordList.set( i, ret ); } You must know ArrayList!

© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content!

© A+ Computer Science - One question on the A test free response will require you to manipulate a 2-dimensional array or a GridWorld grid.

© A+ Computer Science int[][] mat = new int[3][3]; A matrix is an array of arrays

© A+ Computer Science int[][] mat = new int[3][3]; mat[0][1]=2; A matrix is an array of arrays Which array? Which spot? 0 1 2

© A+ Computer Science mat[2][2]=7; mat[0][3]=5; mat[4][1]=

© A+ Computer Science - for( int r = 0; r < mat.length; r++) { for( int c = 0; c < mat[r].length; c++) { mat[r][c] = r*c; } if mat was 3x3

© A+ Computer Science int[][] mat = new int[3][3]; A matrix is an array of arrays # of array s size of each array

© A+ Computer Science - int[][] mat = {{5,7},{5,3,4,6},{0,8,9}}; for( int[] row : mat ) { for( int num : row ) { System.out.print( num + " "); } System.out.println(); } OUTPUT

© A+ Computer Science - public SeatingChart( List studentList, int rows, int cols) { seats = new Student[ rows ] [ cols ]; int i = 0; for( int c = 0; c < seats[0].length; c++) { for( int r = 0; r < seats.length; r++) { if( i < studentList.size() ) seats[r][c] = studentList.get( i++ ); } This could be optimized, but it works perfectly and I assume many students are going to write something close to this.

© A+ Computer Science - public SeatingChart( List studentList, int rows, int cols) { seats = new Student[ rows ] [ cols ]; int i = 0; boolean stop = false; for( int c = 0; c < seats[0].length && !stop; c++) { for( int r = 0; r < seats.length; r++) { if( i < studentList.size() ) seats[r][c] = studentList.get( i++ ); else //added this in to make it more efficient { //not required for AP CS A, but its fun to discuss stop = !stop; break; } Here is the optimized version of ver 1. This not required, but has some fun stuff to discuss.

© A+ Computer Science - public SeatingChart( List studentList, int rows, int cols) { seats = new Student[ rows ] [ cols ]; for( int i = 0; i < studentList.size(); i++ ) { //this algorithmic approach is common on lots //of matrix programming contest problems seats[ i % rows ][ i / rows] = studentList.get( i ); } This algorithm is really cool, but not one that most students would come up with on the exam. I teach this approach to my contest teams as there are often problems that involve storing strings in matrices at many contests.

© A+ Computer Science - public int removeAbsentStudents( int allowedAbsences ) { int count = 0; //I stuck with column / row cuz I felt like it for( int c = 0; c < seats[0].length; c++) { for( int r = 0; r < seats.length; r++) { //must check for null just like the Horse[] question from 2012 if( seats[r][c] != null && seats[r][c].getAbsentCount()>allowedAbsences ) { seats[r][c] = null; count ++; } return count; }

© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content!

© A+ Computer Science - A typical Abstract/Interface question requires that a class be written that extends the abstract class or implements the interface and that all abstract method(s) be implemented.

© A+ Computer Science - Abstract classes are used to define a class that will be used only to build new classes. No objects will ever be instantiated from an abstract class.

© A+ Computer Science - Mammal (abstract class) HumanWhaleCow

© A+ Computer Science - Any sub class that extends a super abstract class must implement all methods defined as abstract in the super class.

© A+ Computer Science - public abstract class APlus { public APlus(int x) //constructor code not shown public abstract double goForIt(); //other fields/methods not shown } Pet Item

© A+ Computer Science - public class PassAPTest extends APlus { public PassAPTest(int x) { super(x); } public double goForIt() { double run=0.0; //write some code - run = x*y/z return run; } //other fields/methods not shown } public abstract class APlus { public APlus(int x) //constructor code not shown public abstract double goForIt(); //other fields/methods not shown }

© A+ Computer Science - public interface Exampleable { int writeIt(Object o); int x = 123; } Methods are public abstract! Variables are public static final!

© A+ Computer Science - public interface Exampleable { public abstract int writeIt(Object o); public static final int x = 123; } Methods are public abstract! Variables are public static final!

© A+ Computer Science - An interface is a list of abstract methods that must be implemented. An interface may not contain any implemented methods. Interfaces cannot have constructors!!!

© A+ Computer Science - Interfaces are typically used when you know what you want an Object to do, but do not know how it will be done. If only the behavior is known, use an interface.

© A+ Computer Science - Abstract classes are typically used when you know what you want an Object to do and have a bit of an idea how it will be done. If the behavior is known and some properties are known, use an abstract class.

© A+ Computer Science - public class Trio implements MenuItem { private MenuItem one, two, three; //I used MenuItem because that’s how I roll! public Trio( Sandwich f, Salad s, Drink t) //Boo – constructor should take 3 MenuItems { one = f; two = s; three = t; } public String getName() { return one + "/" + two + "/" + three; } public double getPrice() { return Math.max( one.getPrice() + two.getPrice(), Math.max( one.getPrice() + three.getPrice(), two.getPrice() + three.getPrice() ) ); } public String toString() { return getName() + " " + getPrice(); }

© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content!

© A+ Computer Science - -Read all 4 questions before writing anything -answer the easiest question 1 st -most times question 1 is the easiest -see if part B calls part A and so on -many times part C consists of A and B calls -write something on every question -write legibly / use PENCIL!!!!!!!!!! -keep track of your time

© A+ Computer Science - -When writing methods -use parameter types and names as provided -do not redefine the parameters listed -do not redefine the methods provided -return from all return methods -return correct data type from return methods

© A+ Computer Science - -When writing a class or methods for a class -know which methods you have -know which instance variables you have -check for public/private on methods/variables -return from all return methods -return correct data type from return methods

© A+ Computer Science - -When extending a class -know which methods the parent contains -have the original class where you can see it -make sure you have super calls -check for public/private on methods/variables -make super calls in sub class methods as needed

© A+ Computer Science - -When extending abstract / implementing interface -know which methods the parent contains -have the original class where you can see it -make sure you have super calls -check for public/private on methods/variables -make super calls in sub class methods as needed -implement all abstract methods in sub class

© A+ Computer Science - ArrayList of References / Strings – get,set,remove,add,size – levels of abstraction GridWorld or Make a Class – location, actor, bug, critter, ROCK, grid, super, abstract Matrix / 2 D Array – nested loops, GridWorld ( grid ) Make a Class / Interfaces / Abstract – implement / extend – not seen this ? type in a few years