Advanced Placement Computer Science


Course Overview
Course Policies
Computer Science AP
   Syllabus 
   Class Schedule
   Homework
   Labs
   Projects
   Extra Credit
   Study Material
   Grades
Computer Science 2 AP
Get Software
Useful Resources
Teacher Information


Extra Credit for Computer Science AP


  • No due date set for the moment, but due before the end of the semester
Prove Einstein wrong!

Einstein famously exclaimed his disbelief in the idea of quantum physics.  Well, it's time to prove quantum physics (or rather a related idea). 

In a famous experiment, the three doors experiment, a person is given a choice of three doors.  Behind one of the three doors is a prize, and behind the other two is nothing.  The person selects a door, and the person running the experiment removes a door other than the one the person selected.  The person running the experiment further gurantees that he or she did NOT remove the door with the prize.  The person who is selecting is left with a dilemma:  does the person stick with their original guess or do they switch to the remaining option.  In reality, if the person switches, there is a 2/3rds chance that they will get the prize... but it's not immediatly obvious why, or if in fact this theory is correct.  You are to write a computer simulation in java that will prove or disprove this idea.  Have the computer randomly select between 3 values to be the prize, and then have it randomly pick again a slot having the computer act as the person selecting.  Then have the computer "remove" one of the other two options making sure not to remove the correct one, and then have the computer either always stick with their choice, or always switch.  Record the number of times, the selector "wins" and how many times they "lose".  Run this simulation a million times, and then report the % of the time they won with their strategy. 

Do this individually and this is worth 5 points.
  • Due on 4/28/04 - Worth a maximum of 30 points in total between all assignments.  Note: the deadline is NOT flexible.  The deadline is 4/28/04 at the start of class.  If you cannot make it to class, email it by the time class would start.
    • Create a new class for the Marine Biology Case Study that extends BoundedEnvironment.
This class will need to allow all fish to move to random locations on the board by DEFAULT without having to modify the Fish class. 

To do this, you will NEED to write a neighborsOf method.  This is defined in the Environment interface, but implemented in the SquareEnvironment, a class which you do NOT have access to.  Just write a method that matches the preconditions/postconditions of the one defined in Environment. 

Demonstrate that this works by modifying SimpleMBSDemo to use it.

This is worth a maximum 5 points.
    • Create a more violent copy of Fish..   Implement neccesary changes to the system so that if a Fish moves, and has another fish in adjacent directly NORTH of the fish, it dies due to being stabbed by invisible daggers.  Change the Fish's color to GRAY if they die.  Make sure it never swims again.  And since we're especially gruesome we allow for Zombies!  Even if a fish is dead, if they are NORTH of the fish and adjacent, the fish still dies.
Demonstrate that this works by modifying SimpleMBSDemo to use it

This is worth a maximum of 5 points
    • Write a program that prompts the user for a number, and then figures out if the number is prime.  Read in the number via JOptionPane, and to figure out if it is prime, find out if there exists any number smaller than it (but larger than 1) that can divide into the number without any remainder.  Make sure you do NOT check all values smaller than the number.  You should not have to check more than the square root of the number being entered (rounded up) tries to determine whether or not a number is prime or not.  You will need to use the Math class.
This is worth a maximum of 5 points
    • Write a program that asks the user for a file name, opens that file, and then calculates the mean, median and mode of the numbers in that file.  The text file (which you have to setup) is formatted with a single double number on each line.  You probably want to read each number into a ArrayList (remember to use wrapper classes...) to do the data manipulation.
Remember, mean means the average. 
Median means if the data were placed into ascending order, the median is the value in the center of that data. 
Mode means the most common number.  (if there are multiple modes, you can report any of the modes)

Display the outputs to the user via System.out.println

This is worth a maximum of 5 points
  • Write a program to track cds in one's collection.  The program should be GUI based, and allow the user to enter in a cd name, an artist name, and a list of songs.  The cd name need be unique, and thus you should make sure the user does not enter in duplicate cd names.  There should be a button to submit the cd into the system (store it internally as an ArrayList) and another one to save the data to cddata.txt, and another one to read in the data from cddata.txt
This is worth a maximum of 5 points
  • This program is based on the previous one, though it can be done independently of the previous one.  Write a GUI based program to allow a user to lookup a cd based on a song title.  Allow the user to enter in the name of a song, and display a list of the possible cds that have those tracks.  Allow the user to select one, and then display all information about the cd.  The data should once again be read in from cddata.txt

This is worth a maximum of 5 points.
  • This program is based on the previous two programs, though it can be done independently of the previous ones.  This program should be a text based program that reads in the cddata.txt and then generates the following text files: songs.txt which lists each song in each cd sorted by the number of cds each song appears on (Hey Jude occurs on multiple Beatles cds for instance); and an artist.txt which lists all artists sorted by the number of albums they have in the system, with each album title listed right after each artist on the same line seperated by commas. 
songs.txt should have this rough format:

Hey Jude
Achy Breaky Heart

artists.txt should have this rough format

Beatles, Please Please Me, Revolver, Rubber Soul, Abbey Road
Rolling Stones, Let It Bleed, Exile on Main Street
Britney Spears, Gag Me Baby One More Time

This is worth a maximum of 5 points

  • You are to write a partial simulator for the game of War. The rules for the game are simple.  You take a deck of cards, randomly sorted, and you split it into two piles.  Each player takes one of the two piles, and for every turn, each player exposes one card, and the player that has the higher card value takes posession of the two cards.  For the purposes of our game, the Ace is considered the highest value cards, and the suites are ranked as follows:  Spades, Diamonds, Hearts and highest is Clubs. 
For the game, you are two write a class for a card that keeps track of what suit and what face value there is for each card.  The class should have a toString() method that returns a String which gives the type of card (2, 3, Jack, etc) and the suit of the card.  The class also should have a compareTo(Object ob) that will return 0 if the two cards have the same value, -1 if you are smaller than the card being passed in as ob and +1 if your card has a higher value than ob.  

You should then write code that will create cards randomly with a randomly selected type (2, 3, Jack, etc) and a randomly selected suit for two "sides", and then display which side wins each round by figuring out which one has the highest value by calling the compareTo method.  And then display each round by using println and the toString() methods.

An example output is as follows:

Player1: Jack of Spades, Player 2: Queen of Hearts
Winner: Player2
Player1: 2 of Hearts, Player 2: 2 of Spades
Winner: Player 1

This is worth a maximum of 5 points

  • Digital audio on computers can be represented as signed integers varying from -32768 to positive 32767 which represent the intensity of the volume at any given instant.  These values are generated thousands of times per second, a process which is known as sampling.  Approximately 44100 samples are taken a second, which means that you record the intensity of the volume 44100 times in a second to try to digitally represent the sound wave.  (this is from the sepecification of an audio cd) 

The consequence of this is that you can manipulate the audio using good old fashioned ints. 

Write a program that takes in "digital audio" from a text file consisting of ints (one per line).  Your program needs to make the music quieter, so you need to divide the volume in "half" and write it to another text file.  (the input file should be input.txt, and the output should be output.txt)

You also need to write another tool which attempts to double the sampling rate of the audio.  To do this, it needs to create virtual samples taking a best guess as to which volume intensity would occur between two.  For instance if the volume is -1000 and in the next sample the volume is 0, the sample that would be between them would probably be -500.  You should then write the resampled audio to output.txt.  The input file should be input.txt, and the formats should match that of the first part of this.

This assignment is worth a maximum of 5 points.

  • 10/30/03 - Worth a maximum of 3 points.  Write a method in a class that extends Vic that takes a single integer as an argument.  This method needs to look a look at a certain number of slots in a sequence (the current instance's sequence), the number being defined by the argument, and move all of the cds in those slots the front of the slots.  (if you are looking at 10 slots, and there are 3 cds, you need to move those 3 to the first 3 slots)   Use the stack!  Then write another method that does the same thing (also with an argument), but moves the cds to the back of the slots you are looking at.  Submit the code of these 2 methods you write by email by midnight on 10/30/03 (between Thursday and Friday).  Late submissions will not be accepted. 
  • 9/25/03 - Worth a maximum of 3 points (graded subjectively based on how creative this is).  Create some kind of picture using the classes used in this chapter (the turtle, the flowers, etc).  The fancier, the better.  Submit the code of the methods (and/or classes if you write classes that extend existing classes) you write by email by 9/25/03.  Late submissions will not be accepted (this is extra credit afterall)
last updated on 5/10/04
Copyright (C) 2004 Jim Casaburi