0% found this document useful (0 votes)
23 views56 pages

Tips On The AP FR 24

The document provides guidelines and tips for answering programming test questions effectively, including strategies for time management and question prioritization. It covers key programming concepts such as class and method creation, array manipulation, and algorithm implementation. Additionally, it emphasizes the importance of understanding method parameters, return types, and the structure of classes and arrays.

Uploaded by

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

Tips On The AP FR 24

The document provides guidelines and tips for answering programming test questions effectively, including strategies for time management and question prioritization. It covers key programming concepts such as class and method creation, array manipulation, and algorithm implementation. Additionally, it emphasizes the importance of understanding method parameters, return types, and the structure of classes and arrays.

Uploaded by

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

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


-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


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


-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


-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


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


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


© A+ Computer Science - www.apluscompsci.com
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


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


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 void simulateOneDay(int numBirds)
{
double r = Math.random()*100;
if( r < 95.0 )
{
int f = (int)(Math.random()*41)+10;
int eaten = f * numBirds;
currentFood = currentFood - eaten;
if( currentFood < 0)
currentFood = 0;
}
else
{
currentFood = 0;
}
}
public int simulateManyDays(int numBirds,
int numDays)
{
int cnt = 0, x = 0;
while( x < numDays && currentFood != 0 )
{
simulateOneDay(numBirds);
cnt++;
x++;
}
return cnt;
}
public int simulateManyDays(int numBirds,
int numDays)
{
int cnt = 0;
for( int x = 0; x < numDays; x++)
{
if( currentFood == 0 )
break;
simulateOneDay(numBirds);
cnt++;

}
return cnt;
}
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


© A+ Computer Science - www.apluscompsci.com
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
public void setSideA(int a )
{
sideA=a;
}

Modifier methods are methods


that change the properties of
an object.
© A+ Computer Science - www.apluscompsci.com
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
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 Scoreboard
{
private String team1;
private String team2;
private int score1;
private int score2;
private boolean active1;
private boolean active2;

public Scoreboard( String t1, String t2 )


{
team1 = t1;
team2 = t2;
score1 = score2 = 0;
active1 = true;
active2 = false;
}
© A+ Computer Science - www.apluscompsci.com
public String getScore()
{
return "" + score1 + " - " + score2 +
" " + (active1 ? team1 : team2);
}

© A+ Computer Science - www.apluscompsci.com


public void recordPlay( int x )
{
if( x > 0 )
{
if( active1 )
score1 += x;
if( active2 )
score2 += x;
}
else
{
active1 = !active1;
active2 = !active2;
}
}
© A+ Computer Science - www.apluscompsci.com
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


© A+ Computer Science - www.apluscompsci.com
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 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
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


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

© A+ Computer Science - www.apluscompsci.com


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

© A+ Computer Science - www.apluscompsci.com


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 boolean isWordChain()
{
for( int i = 0; i < wordList.size()-1; i++)
{
if( !(wordList.get(i+1).contains(
wordList.get(i))))
return false;

}
return true;
}
public ArrayList<String> createList(String target)
{
ArrayList<String> aplus;
aplus = new ArrayList<>();
for( String s : wordList )
{
if(s.startsWith(target))
aplus.add(s.substring(target.length()));
}
return aplus;
}
© A+ Computer Science - www.apluscompsci.com
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


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


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
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
3 0 0 0 0 0
4 0 3 0 0 0

© A+ Computer Science - www.apluscompsci.com


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


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


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
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 Location getNextLoc(int row, int col){
Location bel = null, rt = null;
int bv = 0, rv = 0;
if( row+1 < grid.length){
bel = new Location(row+1,col);
bv = grid[row+1][col];
}
if( col+1 < grid[row].length){
rt = new Location(row,col+1);
rv = grid[row][col+1];
}
if( bel == null )
return rt;
if( rt == null )
return bel;
if( bv < rv )
return bel;
return rt;
}
public int sumPath(int row, int col)
{
int sum = 0;
int rt = grid[row].length-1;
int bot = grid.length-1;
sum += grid[row][col];
while(!(row == bot && col == rt))
{
Location nxt = getNextLoc(row,col);
row = nxt.getRow();
col = nxt.getCol();
sum += grid[row][col];
}
return sum;
}
public int sumPath(int row, int col)
{
int rt = grid[row].length-1;
int bot = grid.length-1;

if(!(row == bot && col == rt))


{
Location nxt = getNextLoc(row,col);
return grid[row][col] +
sumPath(nxt.getRow(), nxt.getCol());
}
return grid[row][col];
}
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


-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


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


-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


-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


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

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