0% found this document useful (0 votes)
47 views53 pages

Tips On The AP FR 21

The document provides guidance and tips for the 2021 AP Computer Science A exam, including for the multiple choice, free response, and programming questions. It emphasizes reading all free response questions before writing, writing something for every question, keeping track of time, using correct return types and parameters, and common free response topics like algorithms/logic, classes, arrays/ArrayLists, and matrices.

Uploaded by

satyamlovessimba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views53 pages

Tips On The AP FR 21

The document provides guidance and tips for the 2021 AP Computer Science A exam, including for the multiple choice, free response, and programming questions. It emphasizes reading all free response questions before writing, writing something for every question, keeping track of time, using correct return types and parameters, and common free response topics like algorithms/logic, classes, arrays/ArrayLists, and matrices.

Uploaded by

satyamlovessimba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

A+ Computer Science

AP Review
2021 AP CS A EXAM
Provided by
A+ Computer Science
Visit us at
www.apluscompsci.com
Full Curriculum Solutions
M/C Review Question Banks
Live Programming Problems
Tons of great content!
www.facebook.com/APlusComputerScience

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

© 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 - 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 - 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 - 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 - 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 - www.apluscompsci.com


Provided by
A+ Computer Science
Visit us at
www.apluscompsci.com
Full Curriculum Solutions
M/C Review Question Banks
Live Programming Problems
Tons of great content!
www.facebook.com/APlusComputerScience

© A+ Computer Science - www.apluscompsci.com


Free Response
Question 1

Algorithms /
Logic

© 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 - www.apluscompsci.com


Algorithms / Logic
for(int aplus=1; aplus<7; aplus+=2)
{
out.println("comp"); OUTPUT
comp
out.println( aplus ); 1
comp
} 3
comp
5

© A+ Computer Science - www.apluscompsci.com


Algorithms / Logic
int run=25; OUTPUT
25
while(run>=10)
loop
{ 20
out.println(run); loop
out.println("loop"); 15
run=run-5; loop
} 10
loop

© A+ Computer Science - www.apluscompsci.com


public int scoreGuess( String guess )
{
int val = 0;
int len = guess.length();
for( int i = 0; i <= secret.length()-len; i+=1)
{
String ck = secret.substring( i, i+len );
if( ck.equals(guess) )
val++;
}
return val*len*len;
}

//This can also be done


//using indexOf which I prefer
public String findBetterGuess(
String guess1, String guess2 )
{
int a = scoreGuess( guess1 );
int b = scoreGuess( guess2 );
if( a > b ) return guess1;
if( b > a ) return guess2;
if( guess1.compareTo( guess2 ) > 0 )
return guess1;
return guess2;
}
Provided by
A+ Computer Science
Visit us at
www.apluscompsci.com
Full Curriculum Solutions
M/C Review Question Banks
Live Programming Problems
Tons of great content!
www.facebook.com/APlusComputerScience

© A+ Computer Science - www.apluscompsci.com


Free Response
Question 2

Make a class

© 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 - 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 - 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 - 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 - www.apluscompsci.com


public class CombinedTable
{
private SingleTable a;
private SingleTable b;

public CombinedTable( SingleTable x, SingleTable y )


{
Make a
}
a = x;
b = y; Class
public boolean canSeat( int num )
{
return num <= ( a.getNumSeats() + b.getNumSeats() - 2);
}

public double getDesirability()


{
double avg = (a.getViewQuality() + b.getViewQuality() ) / 2;
if( a.getHeight() == b.getHeight() )
return avg;
return avg - 10;
}
}

© A+ Computer Science - www.apluscompsci.com


Provided by
A+ Computer Science
Visit us at
www.apluscompsci.com
Full Curriculum Solutions
M/C Review Question Banks
Live Programming Problems
Tons of great content!
www.facebook.com/APlusComputerScience

© A+ Computer Science - www.apluscompsci.com


Free Response
Question 3

ArrayList

© 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 - 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.

34 76 -8 44 22 -998

© 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 - www.apluscompsci.com
ArrayList
List<String> ray; OUTPUT
ray = new ArrayList<String>();
ray.add("hello"); h
ray.add("whoot"); c
ray.add("contests");
out.println(ray.get(0).charAt(0));
out.println(ray.get(2).charAt(0));

ray stores String references.

© 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 - 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 - 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 - www.apluscompsci.com


public void addMembers(
String[] names, int gradYear )
{
for( String n : names )
{
memberList.add(
new MemberInfo( n, gradYear, true) );
}
}
public ArrayList<MemberInfo> removeMembers( int year )
{
ArrayList<MemberInfo> list;
list = new ArrayList<MemberInfo>();
int i = memberList.size()-1;
while( i >= 0 )
{
MemberInfo curr = memberList.get( i );
if( curr.getGradYear() <= year &&
curr.inGoodStanding())
list.add( curr );
if( curr.getGradYear() <= year )
memberList.remove( i );
i--;
}
return list;
}
Free Response
Question 4

Matrices

© 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.
0 1 2

0 0 0 0

1 0 0 0

2 0 0 0

© A+ Computer Science - www.apluscompsci.com


Matrices
A matrix is an array of arrays.

int[][] mat = new int[3][3];


0 1 2

0 0 0 0

1 0 0 0

2 0 0 0

© A+ Computer Science - www.apluscompsci.com


Matrices
A matrix is an array of arrays.
int[][] mat = new int[3][3];
mat[0][1]=2;
0 1 2

Which 0 0 2 0
array?
1 0 0 0
Which
2 0 0 0
spot?
© A+ Computer Science - www.apluscompsci.com
Matrices
0 1 2 3 4
0 0 0 0 5 0 mat[2][2]=7;
1 0 0 0 0 0 mat[0][3]=5;
2 0 0 7 0 0 mat[4][1]=3
0 0 0 0 0
3 0 3 0 0 0
4

© 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;
} 0 0 0
}
0 1 2
if mat was 3x3
0 2 4

© A+ Computer Science - www.apluscompsci.com


Matrices
A matrix is an array of arrays.

int[][] mat = new int[3][3];


0 1 2
# of size
0 0 0 0
array of
1 0 0 0 s each
array
2 0 0 0

© 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 + " ");
}
OUTPUT
System.out.println();
} 57
5346
089
© 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] + " ");
}
OUTPUT
System.out.println();
} 5 7
5346
089
© A+ Computer Science - www.apluscompsci.com
public static boolean isNonZeroRow(
int[][] array2D, int r )
{
for( int v : array2D[r] )
if( v == 0 )
return false;
return true;
}
public static int[][] resize( int[][] array2D )
{
int cnt = numNonZeroRows( array2D );
int[][] box = new int[ cnt ][ 0 ];
int c = 0;
for( int i = 0; i < array2D.length; i++ )
{
//aliasing approach – living dangerously
if( isNonZeroRow( array2D, i ) )
box[c++] = array2D[ i ];
}
return box;
}
public static int[][] resize2( int[][] array2D )
{
int cnt = numNonZeroRows( array2D );
int[][] box = new int[ cnt ][ 0 ];
int c = 0;
for( int i = 0; i < array2D.length; i++ )
{
if( isNonZeroRow( array2D, i ) )
{
//instead of the aliasing option – boring, but it
works
int[] bob = new int[array2D[i].length];
for( int x = 0; x < array2D[ i ].length; x++ )
bob[x] = array2D[i][x];
box[c++] = bob;
}
}
return box;
}
Provided by
A+ Computer Science
Visit us at
www.apluscompsci.com
Full Curriculum Solutions
M/C Review Question Banks
Live Programming Problems
Tons of great content!
www.facebook.com/APlusComputerScience

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

© 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 - 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 - 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 - 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 - 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 - www.apluscompsci.com


A+ Computer Science
AP Review
2021 AP CS A EXAM

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy