Mr. Meinzen - Advanced Placement Computer Science - A

"Success is the ability to go from one failure to another with no loss of enthusiasm." Winston Churchill

APCS-A Handout: Aptitude Questions

 

See which of these questions you can answer correctly...

Question #1

Given the following function definition:

 

public void fun(int n)       
{       
     if (n > 1) 

         fun( n/2 ); 

     System.out.print(n+" "); 
}        

 

The function call fun(16) will yield as output which of the following sequences of numbers?

A. 10 8 6 4 2
B. 16 8 4 2 1
C. 1 2 4 8 16
D. 32 16 8 4 2
E. 2 4 8 16 32

 

Question #2

If b is a boolean variable, then the statement b = (b == false) has what effect?

A. It causes a compile-time error message.
B. It causes a run-time error message.
C. It causes b to have value false regardless of its value just before the statement was executed.
D. It always changes the value of b.
E. It changes the value of b if and only if b had value true just before the statement was executed.

 

APCS-A Handout: Abstract Class Worksheet

 

Given the following two classes, write an abstract class with appropriate abstract & concrete methods/fields that incorporate necessary features of the two classes.

 

public class Wheels
{
	  private double radius = 1.0;
	  private int    width = 14;
  
	  public Wheels(double r) {radius = r;}
    
	  public Wheels(double r, int w) {
		  radius = r;
		  width  = w;
	  }
  
	  public double getArea() {
		  return 3.1415*radius*radius;
	  }
}
  
public class Rollers
{
	  private double radius   = 1.0;
	  private String description;
  
	  public Rollers(double r) {radius = r;}
  
	  public Rollers(double r, String d) {
		  radius       = r;
		  description  = d;
	  }
  
	  public double getArea() {
		  double width = 5;
		  return 2.0*3.1415*radius*width;
	  }
}

 

Write the abstract class RoundShape and the Wheel class using the following class headers:

       
public abstract class RoundShape
{
   ...
}
public class Wheel extends RoundShape
{	
   ...
} 

APCS-A Handout: Data Structures and JCF Modeling

 

Choose the Data Structure that most closely resembles the situation. Be as specific as possible since there may be more than one possible answer.

Possible answers for general data structure: queue, singly linked list, stack, array, tree, binary search tree, priority queue, list, set, map, matrix

Possible answers for Java Collections Framework (JCF): ArrayList, LinkedList, HashSet, HashMap, TreeSet, TreeMap, Collection

 
  • general data structure
  • Java Collections Framework
  • Scenario
1.    

After playing tennis, I put the tennis balls back into the can.

2.    

There is a trendy new restaurant that has a long line of customers waiting to get in, but, if you give the doorman $50, he will sneak you in.

3.    

One day, when I was younger, my sisters and I got bored. We made up a treasure hunt. I hid clues around the house that led to a "treasure" (i.e. candy bar). Then I gave one clue to my sisters. My sisters would read the clue which would give a hint as to where the next clue was hidden. The 2nd clue would tell where the third clue was and so on. The important thing was to make sure all the clues made sense because, if my sisters couldn't figure out one of the clues and I couldn't remember what it meant, we had lost the rest of the cles and the treasure.

4.    

A golf ball "cane" is a way to pick up golf balls without bending over. If I put the bottom of the cane over a ball, I can pick it up. the cane can store several balls and is only one ball wide. When I am ready to get the golf balls out again, I can press a button and the balls will come out the bottom of the cane.

5.    

Consider a golf ball cane (see #4) where the button causes the balls to come out of the top of the cane.

6.    

I collect lots of Beany Babies. I have a sheet of paper which is on a clipboard in the closet. Whenever I buy a new one, I give the new Beany Baby its own name and write it down somewhere on the sheet of paper. Later, if I wonder if I have given one of my Beany Babies a name or not, I have to look all over the sheet to see if I wrote down the name.

7.    

I finally got tired of having to look through that sheet holding the names of my Beany Babies (see #6). So I created a table in a MS Word document that had them all listed in alphabetical order. Now, I can add more Beany Babies (or, I suppose, delete one if a I give one away). The MS Word table will let me add babies anywhere in the list that I wish.

8.    

Part of an administrative chart for a school is below:

9.    

You create a video game and show a "Top Ten" list. If someone scores high enough to make the list, the tenth name on the list disappears.

10.    

When I first started teaching, we had an emergency phone list. Then, if there was anything urgent such as a school cancellation due to snow, the top person on the list would contact the two people below her. Each of those people would contact two people below them and so on. That way, each person was contacted quickly, yet no one had to make more than two calls.

11.

 

 

I am making a game where there are multiple endings depending on decisions you make throughout the game.

12.

 

 

A gardener enjoys planting trees in her neighborhood. She makes sure to plant one tree in each lot before she plants another tree in the same lot.

13.

 

 

A Arborist enjoys creating a formal garden. He makes sure to plant one row of trees before continuing on with the second row and so on until the lot has a formal rectangular arrangment of trees.

 

Now its your turn: Write an example like the above. Also, write the name of the data structure that your example models. Your answers should contain at least two complete sentences. You should also consider (and explain) other possible data structures that may be used along with your model that could be appropriate.

My Example:

 

 

 

Type of Data Structure that I am modeling

 

 

Why my model is appropriate to my example.

 

 

APCS-A Handout: Maps & Sets Modeling 

  • Determine if, in a given situation,
    • the data structure should be arranged as a Tree or a Hash table
    • then determine if it should be organized as a Map or Set.
    • Give Big-Oh time estimates for :
      1. inserting an element,
      2. retrieving an element and
      3. sorting
  • Please note that, for any given scenario, more information may be needed to give a definitive answer. In other words, there may be several correct answers from the given information. Assume your teacher will give additional information based upon your questions/assumptions for each scenario.
  •  

    Scenario

    Tree or Hash

    Set or Map

    O(insert)

    O(get)

    O(sort)

    1 A city may have several zip codes. Implement a group of cities with corresponding zip codes.          
    2 A word may have several definitions. Implement a simple dictionary.          
    3 Cars are to organized by date of manufacturing or VIN number.          
    4 A function where the independant variable (i.e. x) is the number of units consumed and the dependant variable (i.e. y) is profit.          
    5 A function where where the independant variable is an address and the dependant variable is name of a resident.          
    6 A relation where Objects are stored in specific memory locations          
    7 A dictionary where one word may have several definitions and one definition may apply to more than one word.          
    8 A translator where an English word is translated to a single French word          
    9 In order to keep statistics for football, every player has a record of their percentage of "effectiveness". What data structure(s)would you use to optimize the sorting of players by their "effective" percentage?          

APCS-A Handout: Exam Preparation Scores using the Practice Workbook

Fill out the table with the scores (percentage) and number of problems completed each hour.

Quiz/Exam

Student:

Student:

Student:

Student:

Student:

Control Structures

 

 

 

 

 

Boolean Algebra

 

 

 

 

 

Arrays

 

 

 

 

 

Strings

 

 

 

 

 

Standard Classes & Interfaces I

 

 

 

 

 

ArrayList

 

 

 

 

 

Program Design

 

 

 

 

 

Inheritance & Composition

 

 

 

 

 

Recursion

 

 

 

 

 

Stacks, Queues, Priority Queues

 

 

 

 

 

Linked Lists

 

 

 

 

 

Binary Trees

 

 

 

 

 

Standard Classes & Interfaces II

 

 

 

 

 

Algorithmic Analysis

 

 

 

 

 

Exam I (A)

 

 

 

 

 

Exam II (A)

 

 

 

 

 

Exam I (AB)

 

 

 

 

 

Exam II (AB)