Download presentation
Presentation is loading. Please wait.
Published byΧρυσάνθη Αρβανίτης Modified over 5 years ago
1
A+ Computer Science AP Review 2019 AP CS A EXAM
2
Provided by A+ Computer Science
Visit us at Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! © A+ Computer Science -
3
© A+ Computer Science - www.apluscompsci.com
Multiple Choice -answer the easiest question 1st -work through the test more than once -use the test to take the test -work more time intensive problems last -bubble answers on answer sheet as you go -answer every question -keep track of your time minutes © A+ Computer Science -
4
© A+ Computer Science - www.apluscompsci.com
Free Response -Read all 4 questions before writing anything -answer the easiest question 1st -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 -
5
© A+ Computer Science - www.apluscompsci.com
Free Response -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 -
6
© A+ Computer Science - www.apluscompsci.com
Free Response -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 -
7
© A+ Computer Science - www.apluscompsci.com
Free Response -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 -
8
© A+ Computer Science - www.apluscompsci.com
Free Response Topics Algorithms / Logic – ifs, loops, methods Make a Class – create a class Array/ArrayList – get,set,remove,add,size - [],length Matrices – nested loops - array of arrays concepts © A+ Computer Science -
9
Provided by A+ Computer Science
Visit us at Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! © A+ Computer Science -
10
Free Response Question 1
Algorithms / Logic © A+ Computer Science -
11
© A+ Computer Science - www.apluscompsci.com
Algorithms / Logic Algorithm problems often use array and strings, but like this year, they sometimes just use simple loops and method calls. © A+ Computer Science -
12
© A+ Computer Science - www.apluscompsci.com
Algorithms / Logic for(int aplus=1; aplus<7; aplus+=2) { out.println("comp"); out.println( aplus ); } OUTPUT comp 1 comp 3 comp 5 This loop starts run at 1 and increments run by two each iteration. The loop will continue to run as long as run is less than 7. The loop will stop when the condition run<7 fails. The condition will fail when run equals 7. run begins with the value 1 Iteration 1 – print run(1) run = 1 + 2 Iteration 2 – print run(3) run = 3 + 2 Iteration 3 – print run(5) run = 5 + 2 The loop condition fails when run reaches the value 7 as 7 is not less than 7. © A+ Computer Science -
13
© A+ Computer Science - www.apluscompsci.com
Algorithms / Logic OUTPUT 25 loop 20 loop 15 loop 10 loop int run=25; while(run>=10) { out.println(run); out.println("loop"); run=run-5; } As long as run is less than or equal to 10 ( run<=10 ), the loop will iterate. For each iteration, run is displayed, loop is displayed, and run is decreased by 5. run begins with the value 25 Iteration 1 – print(25) print(loop) run = 25-5 Iteration 2 – print(20) print(loop) run = 20-5 Iteration 3 – print(15) print(loop) run = 15-5 Iteration 4 – print(10) print(loop) run = 10-5 The loop condition fails when run reaches the value 5 as 5 is not greater than or equal to 10. © A+ Computer Science -
14
public static numberOfLeapYears( int year1, int year2 )
{ int count = 0; for( int aplus = year1; aplus<=year2; aplus++) if( isLeapYear( aplus ) ) count++; } return count; } 2019 Question 1 Part A
15
public static int dayOfWeek( int m, int d, int y )
{ return ( firstDayOfYear( y ) + dayOfYear( m, d, y ) – 1 ) % 7; } 2019 Question 1 Part B
16
Provided by A+ Computer Science
Visit us at Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! © A+ Computer Science -
17
Free Response Question 2
Make a class © A+ Computer Science -
18
© A+ Computer Science - www.apluscompsci.com
Make a Class 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 -
19
© A+ Computer Science - www.apluscompsci.com
Make a Class public void setSideA(int a ) { sideA=a; } Modifier methods are methods that change the properties of an object. © A+ Computer Science -
20
© A+ Computer Science - www.apluscompsci.com
Make a Class 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 -
21
© A+ Computer Science - www.apluscompsci.com
Make a Class public class Triangle { private int sideA; private int sideB; private int sideC; Instance variables store the state information for an object. © A+ Computer Science -
22
© A+ Computer Science - www.apluscompsci.com
public class StepTracker { private int steps, adays, min_steps, days; public StepTracker(int m) { min_steps=m; steps=adays=days=0; } public int activeDays() { return adays; public double averageSteps() { return steps==0?0.0:(double)steps/days; //could just use an if } //felt like living on public void addDailySteps(int st) { //the wild side steps+=st; days++; if(st>=min_steps) { adays++; Make a Class 2019 Question 2 © A+ Computer Science -
23
Provided by A+ Computer Science
Visit us at Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! © A+ Computer Science -
24
Free Response Question 3
ArrayList © A+ Computer Science -
25
© A+ Computer Science - www.apluscompsci.com
ArrayList A typical ArrayList question involves putting something into an ArrayList and removing something from an ArrayList. 34 76 -8 44 22 -998 © A+ Computer Science -
26
© A+ Computer Science - www.apluscompsci.com
ArrayList 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. ArrayList can store a reference to any type of Object. ArrayList was built using an array[] of object references. 34 76 -8 44 22 -998 © A+ Computer Science -
27
frequently used methods © A+ Computer Science - www.apluscompsci.com
ArrayList frequently used methods Name Use 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 -
28
© A+ Computer Science - www.apluscompsci.com
ArrayList List<String> ray; ray = new ArrayList<String>(); ray.add("hello"); ray.add("whoot"); ray.add("contests"); out.println(ray.get(0).charAt(0)); out.println(ray.get(2).charAt(0)); OUTPUT h c In the example above, ray is an ArrayList that stores String references. Casting would not be required to call non-Object methods on ray. ray.add(0,"hello"); ray.add(1,"chicken"); out.println(ray.get(0).charAt(0)); out.println(ray.get(1).charAt(5)); ray stores String references. © A+ Computer Science -
29
© A+ Computer Science - www.apluscompsci.com
ArrayList int spot=list.size()-1; while(spot>=0) { if(list.get(spot).equals("killIt")) list.remove(spot); spot--; } © A+ Computer Science -
30
© A+ Computer Science - www.apluscompsci.com
ArrayList for(int spot=list.size()-1; i>=0; i--) { if(list.get(spot).equals("killIt")) list.remove(spot); } © A+ Computer Science -
31
© A+ Computer Science - www.apluscompsci.com
ArrayList int spot=0; while(spot<list.size()) { if(list.get(spot).equals("killIt")) list.remove(spot); else spot++; } © A+ Computer Science -
32
public ArrayList<String> getDelimitersList(
String[] tokens) { ArrayList<String> fun; fun = new ArrayList<String>(); for( String s : tokens ) if( s.equals( openDel ) || s.equals( closeDel) ) fun.add( s ); } return fun; 2019 Question 3 Part A
33
public boolean isBalanced(ArrayList<String> delimiters)
{ int closeCount = 0; int openCount = 0; for( String s : delimiters ) if( s.equals( openDel ) ) openCount++; } else if( s.equals( closeDel ) ) closeCount++; if( closeCount > openCount ) return false; return closeCount == openCount; 2019 Question 3 Part B
34
Free Response Question 4
Matrices © A+ Computer Science -
35
© A+ Computer Science - www.apluscompsci.com
Matrices Typically, 1 question on the A test free response will require that students manipulate a 2-dimensional array. 2 © A+ Computer Science -
36
© A+ Computer Science - www.apluscompsci.com
Matrices A matrix is an array of arrays. int[][] mat = new int[3][3]; 2 Each spot in an matrix stores the location/address of an array. mat[0] stores the location / address of a one-dimensional array. © A+ Computer Science -
37
© A+ Computer Science - www.apluscompsci.com
Matrices A matrix is an array of arrays. int[][] mat = new int[3][3]; mat[0][1]=2; 2 2 Which array? Each spot in an matrix stores the location/address of an array. mat[0] stores the location / address of a one-dimensional array. mat[0][1]=2; This line sets mat[0] spot 1 to 2. Which spot? © A+ Computer Science -
38
© A+ Computer Science - www.apluscompsci.com
Matrices mat[2][2]=7; mat[0][3]=5; mat[4][1]=3 5 7 3 mat[2] stores the location / address of a one-dimensional array. mat[2][2]=7; This line sets mat[2] spot 2 to 7. © A+ Computer Science -
39
© A+ Computer Science - www.apluscompsci.com
Matrices for( int r = 0; r < mat.length; r++) { for( int c = 0; c < mat[r].length; c++) mat[r][c] = r*c; } 1 2 4 if mat was 3x3 © A+ Computer Science -
40
© A+ Computer Science - www.apluscompsci.com
Matrices A matrix is an array of arrays. int[][] mat = new int[3][3]; # of arrays size of each array 2 © A+ Computer Science -
41
© A+ Computer Science - www.apluscompsci.com
Matrices – for each 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(); The for each loop works quite well as tool to print a matrix. OUTPUT © A+ Computer Science -
42
© A+ Computer Science - www.apluscompsci.com
Matrices – for loop int[][] mat = {{5,7},{5,3,4,6},{0,8,9}}; for( int r = 0; r < mat.length; r++ ) { for( int c = 0; c < mat[r].length; c++ ) System.out.print( mat[r][c] + " "); } System.out.println(); The for each loop works quite well as tool to print a matrix. OUTPUT © A+ Computer Science -
43
2019 Question 4 part A public LightBoard(int numRows, int numCols) {
lights=new boolean[numRows][numCols]; for(int r=0;r<numRows;r++) for(int c=0;c<numCols;c++) lights[r][c]=(int)(Math.random()*10)<=3; } 2019 Question 4 part A
44
2019 Question 4 part B public boolean evaluateLight(int row, int col)
{ boolean light=lights[row][col]; int n=0; for(int c=0;c<lights[0].length;c++) if(lights[row][c]) n++; if(light && n%2==0) return false; else if(!light && n%3==0) return true; return light; } 2019 Question 4 part B
45
Provided by A+ Computer Science
Visit us at Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! © A+ Computer Science -
46
© A+ Computer Science - www.apluscompsci.com
Multiple Choice -answer the easiest question 1st -work through the test more than once -use the test to take the test -work more time intensive problems last -bubble answers on answer sheet as you go -answer every question -keep track of your time minutes © A+ Computer Science -
47
© A+ Computer Science - www.apluscompsci.com
Free Response -Read all 4 questions before writing anything -answer the easiest question 1st -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 -
48
© A+ Computer Science - www.apluscompsci.com
Free Response -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 -
49
© A+ Computer Science - www.apluscompsci.com
Free Response -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 -
50
© A+ Computer Science - www.apluscompsci.com
Free Response -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 -
51
© A+ Computer Science - www.apluscompsci.com
Free Response Topics Algorithms / Logic – ifs, loops, methods Make a Class – create a class Array/ArrayList – get,set,remove,add,size - [],length Matrices – nested loops - array of arrays concepts © A+ Computer Science -
52
A+ Computer Science AP Review 2019 AP CS A EXAM
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.