© 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 TOPICS TO DISCUSS.equals() == instanceof operator compareTo Interfaces Abstract Classes.
Advertisements

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,
Loops Notes adapted from Dr. Flores. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while”
Arrays, Loops weeks 4-6 (change from syllabus for week 6) Chapter 4.
© A+ Computer Science - ArrayList © A+ Computer Science - Lab 16.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 4: Strings & Arrays Sanjay Goel.
CS 307 Fundamentals of Computer ScienceIterators 1 Topic 14 Iterators "First things first, but not necessarily in that order " -Dr. Who.
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.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
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.
GCOC – A.P. Computer Science A. College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose,
© 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
© 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.
Data Structures & Algorithms
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
1 Java linked list. Java linked list - definition ▪ Often in programming we are required to systematically store some type of information. A prime example.
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.
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.
Contest Algorithms January 2016 Pseudo-code for backtracking search, and three examples (all subsets, permutations, and 8- queens). 4. Backtracking 1Contest.
COMP More About Arrays Yi Hong June 05, 2015.
Java linked list.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
© A+ Computer Science - Visit my site at Full Curriculum Solutions M/C Review Question Banks Live Programming.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
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.
Sequential (Linear) Binary Selection** Insertion** Merge.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
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.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
© 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 - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Magpie Magpie is a lab that focuses on classes, randomness, and Strings. This lab will make sure that you.
© A+ Computer Science - Elevens is a lab about classes and Lists. List is a major concept being tested by the Elevens lab. Elevens.
Lecture 18: Nested Loops and Two-Dimensional Arrays
Objects as a programming concept
© A+ Computer Science - Magpie Chatbot Lab © A+ Computer Science -
Topic Dimensional Arrays
A+ Computer Science AP Review 2018 AP CS A EXAM
Chapter 12 Recursion (methods calling themselves)
Multiple Choice -answer the easiest question 1st
Lesson A4 – Object Behavior
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
© A+ Computer Science - What is a LOOP? © A+ Computer Science -
© A+ Computer Science - OOP © 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
Methods Copying Autoboxing
Lecture 13: Two-Dimensional Arrays
© A+ Computer Science - Classes And Objects © A+ Computer Science -
© A+ Computer Science - OOP Pieces © A+ Computer Science -
CIS 199 Final Review.
A+ Computer Science AP Review 2019 AP CS A EXAM
What is a String? String s = "compsci"; s c o m p s i
First Semester Review.
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 - -answer the easiest question 1 st -cycle through the test more than once -use the test to take the test -save long tracing problems for last -bubble as you go -answer every question -keep track of your time - 90 minutes

© 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 - Make a Class - Strings / List – create a basic class with instance variables, constructors, and methods ArrayList of References / Strings – get,set,remove,add,size – levels of abstraction Array / Array or Arrays – for and for each loops, nested loops, array of arrays concepts List of Strings – String Love Fest III – More List manipulation and more Strings

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

© A+ Computer Science -

public Triangle(int a, int b, int c) { sideA=a; sideB=b; sideC=c; } Constructors are similar to methods. Constructors set the properties of an object to an initial state.

© A+ Computer Science - public void setSideA(int a ) { sideA=a; } Modifier methods are methods that change the properties of an object.

© A+ Computer Science - public int getSideA() { return sideA; } Accessor methods are methods that retrieve or grant access to the properties of an object, but do not make any changes.

© A+ Computer Science - public class Triangle { private int sideA; private int sideB; private int sideC; Instance variables store the state information for an object.

© A+ Computer Science - public class HiddenWord { private String word; public HiddenWord( String w ) { word = w; } public String getHint( String guess ) { String ret = ""; for( int i = 0; i < word.length(); i++) { if( word.substring(i,i+1).equals(guess.substring(i,i+1)) ) ret += word.substring( i, i+1); else if( word.indexOf( guess.substring(i,i+1))!=-1) ret += "+"; else ret += "*"; } return ret; } }

© A+ Computer Science s String s = "compsci"; A string is a group of characters. The first character in the group is at spot 0. compsci

© A+ Computer Science - String frequently used methods NameUse substring(x,y)returns a section of the string from x to y not including y substring(x)returns a section of the string from x to length-1 length()returns the # of chars charAt(x)returns the char at spot x indexOf(c)returns the loc of char c in the string, searching from spot 0 to spot length-1 lastIndexOf(c)returns the loc of char c in the string, searching from spot length-1 to spot 0

© A+ Computer Science - String frequently used methods NameUse equals(s)checks if this string has same chars as s compareTo(s)compares this string and s for >,<, and == trim()removes leading and trailing whitespace replaceAll(x,y)returns a new String with all x changed to y toUpperCase()returns a new String with uppercase chars toLowerCase()returns a new String with lowercase chars

© A+ Computer Science - String sent = "alligators rule"; String find = "gato"; System.out.println( sent.indexOf( find ) ); System.out.println( sent.indexOf( "dog" ) ); System.out.println( sent.substring( 3, 6 ) ); System.out.println( sent.substring( 6 ) ); OUTPUT 4 -1 iga tors rule

public class RandomStringChooser { private ArrayList choices; public RandomStringChooser( String[] list ) { choices = new ArrayList (); for( String s : list ) { choices.add( s ); } public String getNext( ) { int sz = choices.size(); if( sz == 0 ) return "NONE"; int spot = (int)(Math.random()*sz); return choices.remove( spot ); }

public RandomLetterChooser( String str ) { super( getSingleLetters( str ) ); }

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

© A+ Computer Science -

s String s = "compsci"; A string is a group of characters. The first character in the group is at spot 0. compsci

© A+ Computer Science - String frequently used methods NameUse substring(x,y)returns a section of the string from x to y not including y substring(x)returns a section of the string from x to length-1 length()returns the # of chars charAt(x)returns the char at spot x indexOf(c)returns the loc of char c in the string, searching from spot 0 to spot length-1 lastIndexOf(c)returns the loc of char c in the string, searching from spot length-1 to spot 0

© A+ Computer Science - String frequently used methods NameUse equals(s)checks if this string has same chars as s compareTo(s)compares this string and s for >,<, and == trim()removes leading and trailing whitespace replaceAll(x,y)returns a new String with all x changed to y toUpperCase()returns a new String with uppercase chars toLowerCase()returns a new String with lowercase chars

© A+ Computer Science - String sent = "alligators rule"; String find = "gato"; System.out.println( sent.indexOf( find ) ); System.out.println( sent.indexOf( "dog" ) ); System.out.println( sent.substring( 3, 6 ) ); System.out.println( sent.substring( 6 ) ); OUTPUT 4 -1 iga tors rule

© 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++; }

public LogMessage( String message ) { //split would work great for this int spot = message.indexOf( ":" ); machineId = message.substring( 0, spot ); description = message.substring( spot + 1 ); } Somebody loves Strings!

public boolean containsWord( String keyword ) { //contributed by my 9th grader int pos1 = description.indexOf( keyword + " " ); int pos2 = description.indexOf( " " + keyword ); int pos3 = description.indexOf( " " + keyword + " " ); int end = description.length() - keyword.length()-1; if( end+1 == 0 ) return description.equals(keyword); if( pos1 == 0 ) return true; if( pos2 == end && end != -1) return true; if( pos3 > -1 ) return true; return false; } Somebody loves Strings!

public boolean containsWord( String keyword ) { String[] stuff = description.split(" "); for( String s : stuff ) if( s.equals( keyword) ) return true; return false; } Somebody loves Strings!

public List removeMessages(String keyword) { ArrayList a=new ArrayList (); for(int y=0;y<messageList.size();y++) { if(messageList.get(y).containsWord(keyword)) { a.add(messageList.remove(y--)); } return a; } 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

public boolean toBeLabeled( int r, int c, boolean[][] blackSquares ) { return( ! blackSquares[r][c] && ( r==0 || c==0 || blackSquares[r][c-1] || blackSquares[r-1][c]) ); }

public CrosswordPuzzle( boolean[][] blackSquares ) { int k=0; puzzle = new Square[ blackSquares.length ] [ blackSquares[0].length ]; for(int r=0;r<puzzle.length;r++) { for(int c=0;c<puzzle[r].length;c++) { if(blackSquares[r][c]) puzzle[r][c]=new Square(true,0); else if(toBeLabeled(r,c,blackSquares)) puzzle[r][c]=new Square(false,++k); else puzzle[r][c]=new Square(false,0); }

© A+ Computer Science -

s String s = "compsci"; A string is a group of characters. The first character in the group is at spot 0. compsci

© A+ Computer Science - String frequently used methods NameUse substring(x,y)returns a section of the string from x to y not including y substring(x)returns a section of the string from x to length-1 length()returns the # of chars charAt(x)returns the char at spot x indexOf(c)returns the loc of char c in the string, searching from spot 0 to spot length-1 lastIndexOf(c)returns the loc of char c in the string, searching from spot length-1 to spot 0

© A+ Computer Science - String frequently used methods NameUse equals(s)checks if this string has same chars as s compareTo(s)compares this string and s for >,<, and == trim()removes leading and trailing whitespace replaceAll(x,y)returns a new String with all x changed to y toUpperCase()returns a new String with uppercase chars toLowerCase()returns a new String with lowercase chars

© A+ Computer Science - String sent = "alligators rule"; String find = "gato"; System.out.println( sent.indexOf( find ) ); System.out.println( sent.indexOf( "dog" ) ); System.out.println( sent.substring( 3, 6 ) ); System.out.println( sent.substring( 6 ) ); OUTPUT 4 -1 iga tors rule

© 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++; }

public static int totalLetters( List wordList ) { int sum = 0; for( String s : wordList ) { sum += s.length(); } return sum; }

public static int basicGapWidth( List wordList, int formattedLen ) { int size = totalLetters( wordList ); int diff = formattedLen - size; return diff / (wordList.size()-1); }

public static String format( List wordList, int formattedLen ) { String form = ""; int left = leftoverSpaces( wordList, formattedLen); int wid = basicGapWidth( wordList, formattedLen); for(int i = 0; i < wordList.size()-1; i++) { form += wordList.get(i); for( int j = 0; j < wid; j++) { form += " "; } if( i < left ) { form += " "; } form += wordList.get( wordList.size()-1 ); return form; }

public static String format( List wordList, int formattedLen ) { ArrayList cool; cool = new ArrayList ( wordList ); String form = ""; String spaces = ""; for( int j = 0; j < basicGapWidth( cool, formattedLen); j++) { spaces += " "; } for(int i = 0; i < cool.size()-1; i++) { cool.set( i, cool.get(i) + spaces ); } int left = leftoverSpaces( cool, formattedLen); for(int i = 0; i < left && i < cool.size(); i++) { cool.set( i, cool.get(i)+" " ); } for( String s : cool ) { form += s; } return form; }

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

© A+ Computer Science - -answer the easiest question 1 st -cycle through the test more than once -use the test to take the test -save long tracing problems for last -bubble as you go -answer every question -keep track of your time – 90 minutes

© 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 – 90 minutes

© 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 - Make a Class - Strings / List – create a basic class with instance variables, constructors, and methods ArrayList of References / Strings – get,set,remove,add,size – levels of abstraction Array / Array or Arrays – for and for each loops, nested loops, array of arrays concepts List of Strings – String Love Fest III – More List manipulation and more Strings