AP Computer Science A
2014 Scoring Guidelines
© 2014 The College Board. College Board, Advanced Placement Program, AP, AP Central, and the acorn logo
are registered trademarks of the College Board.
Visit the College Board on the Web: www.collegeboard.org.
AP Central is the official online home for the AP Program: apcentral.collegeboard.org.
o
o
o
o private public
o public
o
o
o [] () <>
o = ==
o [] get
o length/size String List ArrayList ( )
o []
o [i,j] [i][j]
o int[size] nums = new int[size];
o ;
o { } { }
o ( )
o ( ) if while
ArayList ArrayList
Bug bug; Bug.move()
bug.move()
scrambleWord
word,
scrambleOrRemove
wordList
scrambleWord
public static String scrambleWord(String word){
int current = 0;
String result="";
while (current < word.length()-1){
if (word.substring(current,current+1).equals("A") &&
!word.substring(current+1,current+2).equals("A")){
result += word.substring(current+1,current+2);
result += "A";
current += 2;
}
else {
result += word.substring(current,current+1);
current++;
}
}
if (current < word.length()){
result += word.substring(current);
}
return result;
}
public static void scrambleOrRemove(List<String> wordList){
int index = 0;
while (index < wordList.size()){
String word=wordList.get(index);
String scrambled=scrambleWord(word);
if (word.equals(scrambled)){
wordList.remove(index);
}
else {
wordList.set(index,scrambled);
index++;
}
}
}
Director
Rock
class Director extends Rock
Director(){ }
Color.RED setColor super(Color.RED)
act
act
getGrid
setDirection
public class Director extends Rock
{
public Director()
{
super(Color.RED);
}
public void act()
{
if (getColor().equals(Color.GREEN))
{
ArrayList<Actor> neighbors = getGrid().getNeighbors(getLocation());
for (Actor actor : neighbors)
{
actor.setDirection(actor.getDirection() + Location.RIGHT);
}
setColor(Color.RED);
}
else
{
setColor(Color.GREEN);
}
}
}
SeatingChart
SeatingChart
seats = new Student[rows][cols];
studentList studentList
studentList
seats
removeAbsentStudents 4
seats
getAbsenceCount() Student
null
allowedAbsences
seats studentList
public SeatingChart(List<Student> studentList, int rows, int cols){
seats=new Student[rows][cols];
int studentIndex=0;
for (int col = 0; col < cols; col++){
for (int row = 0; row < rows; row++){
if (studentIndex < studentList.size()){
seats[row][col] = studentList.get(studentIndex);
studentIndex++;
}
}
}
}
public SeatingChart(List<Student> studentList, int rows, int cols){
seats=new Student[rows][cols];
int row=0;
int col=0;
for (Student student : studentList){
seats[row][col]=student;
row++;
if (row==rows){
row=0;
col++;
}
}
}
public int removeAbsentStudents(int allowedAbsences){
int count = 0;
for (int row=0; row < seats.length; row++){
for (int col=0; col < seats[0].length; col++){
if (seats[row][col] != null &&
seats[row][col].getAbsenceCount() > allowedAbsences){
seats[row][col]=null;
count++;
}
}
}
return count;
}
Trio
MenuItem
public class Trio implements MenuItem
private
public Trio(Sandwich sandwich, Salad salad, Drink drink)
public String getName(){ } public double getPrice(){ }
getName
getName
getPrice
getPrice
public class Trio implements MenuItem {
private Sandwich sandwich;
private Salad salad;
private Drink drink;
public Trio(Sandwich s, Salad sal, Drink d){
sandwich = s;
salad = sal;
drink = d;
}
public String getName(){
return sandwich.getName() + "/" + salad.getName() + "/" +
drink.getName() + " Trio";
}
public double getPrice(){
double sandwichPrice = sandwich.getPrice();
double saladPrice = salad.getPrice();
double drinkPrice = drink.getPrice();
if (sandwichPrice <= saladPrice && sandwichPrice <= drinkPrice)
return saladPrice + drinkPrice;
else if (saladPrice <= sandwichPrice && saladPrice <= drinkPrice)
return sandwichPrice + drinkPrice;
else
return sandwichPrice + saladPrice;
}
}
public class Trio implements MenuItem {
private String name;
private double price;
public Trio(Sandwich s, Salad sal, Drink d){
double sandwichPrice = s.getPrice();
double saladPrice = sal.getPrice();
double drinkPrice = d.getPrice();
if (sandwichPrice <= saladPrice && sandwichPrice <= drinkPrice)
price = saladPrice + drinkPrice;
else if (saladPrice <= sandwichPrice && saladPrice <= drinkPrice)
price = sandwichPrice + drinkPrice;
else
price = sandwichPrice + saladPrice;
name = s.getName()+ "/" + sal.getName()+ "/" + d.getName()+ " Trio";
}
public String getName(){
return name;
}
public double getPrice(){
return price;
}
}