Difference between revisions of "IB Computer Science 2"

From WLCS
(Friday (10/8/10))
Line 32: Line 32:
 
# What is the average # of comparisons?
 
# What is the average # of comparisons?
 
* Binary Search Advantages & Disadvantages
 
* Binary Search Advantages & Disadvantages
 +
 +
* Use the following [[Media:IBCS2 Roster]]
 +
* Convert [[Media:LinearSearch.java]] and [[Media:BinarySearch.java]] so that it searches for a String name
  
 
== Wednesday (10/6/10) ==
 
== Wednesday (10/6/10) ==

Revision as of 11:53, 8 October 2010

Friday (10/8/10)

Warmup:

  • Turn in Analyzing the Problem section
  • What are the steps necessary in order to use a dictionary?
    • Write it out in a text editor.

Agenda:

  • Peer edit analyzing the problem
  • Review of Linear Search
  • Download Media:LinearSearch.java
  • Fill in the commented parts of LinearSearch.java and demo a working linear search to Mr. Bui
  • Linear Search performance evaluation
  1. What is the best case scenario? i.e. What is the minimum # of comparisons?
  2. What is the worst case scenario? i.e. What is the maximum # of comparisons?
  3. What is the average # of comparisons?
  4. Can we do better than a linear search?
  • Introduction to Binary Search
  1. Assume sorted list
  2. Go to the middle point
  3. If the middle element matches the key, then the search is over
  4. If the key is less than middle element, go to the left (down), else go to the right (up)
  5. Repeat steps 2-4 until the key is found or when the left and right bounds pass each other
  1. What is the best case scenario? i.e. What is the minimum # of comparisons?
  2. What is the worst case scenario? i.e. What is the maximum # of comparisons?
  3. What is the average # of comparisons?
  • Binary Search Advantages & Disadvantages

Wednesday (10/6/10)

Warmup:

  • Pickup 5 playing cards from Mr. Bui
  • Use the BubbleSort algorithm to hand-sort the cards from least to greatest

Agenda:

  • Turn in field trip slips.
  • Demo all programs. Interims are due today.
  • Work on Dossier: Analyzing the Problem

Homework:

  • Analyzing the Problem due Friday (10/8/08)Due Friday (10/8/08)
  • Any missing assignments

Monday (10/4/10)

Warmup:

Agenda:

  • SelectionSort Review
  • Introduction to Bubble Sort
  1. Initialize the front to be the top or beginning of the array
  2. Now go to the bottom/end of the array
  3. Compare the two adjacent elements to see if they are in proper sequential order
    1. Swap the elements if they are out of order (bigger number to the left of smaller number)
  4. Move to the next pair of adjacent elements/numbers
  5. Repeat steps 3 and 4 until the smallest number has "floated" to the top/front
  6. After you traverse the entire array
    1. Move the front so that the sorted numbers are ignored
    2. Go back to the end of the array
    3. Repeat steps 2 through 6 for the unsorted part of the array

Homework:

  • Analyzing the Problem due Friday (10/8/10)

Thursday (9/30/10)

Warmup:

  • Pickup 5 playing cards from Mr. Bui
  • Use the SelectionSort algorithm to hand-sort the cards from least to greatest

Agenda:

  • Turn in field trip slips
  • Turn in quiz corrections
  • Demo AddressBook class lab assignment
  • Demo ArrayPractice exercises
  • Demo SelectionSort
  • Add a (s)ort option to your AddressBook
    • In order to compare Strings:
if (str1.compareTo(str2) < 0)
{
  System.out.println(str1 + " goes before " + str2);
}
  • So inside your AddressBook, you'd have something like this:
if (myContacts[i].getLastName().compareTo(myContacts[j].getLastName()) < 0)

Back To School Night (9/29/10)

Tuesday (9/28/10)

Warmup:

  • Create a Java file with a main() called SelectionSort
  • Create an array of 20 ints
  • Use your own numbers in the array

Agenda:

  • Introduction to Selection Sort
  1. Find the smallest element
  2. Move to the front of the array (swap with front)
  3. Repeat Steps 1&2, but ignoring the sorted front

Friday (9/24/10)

Warmup:

  • You will be creating a user interface menu for use with your AddressBook
  • Open / create your AddressBook's main method
  • Inside the main method, create an AddressBook variable:
AddressBook book = new AddressBook();
  • Print out a message that explains the program (e.g. "Welcome to YOUR_NAME's address book!")
  • Print out a menu with the following options:
(a)dd to address book
(f)ind a Contact
(p)rint address book
(q)uit

What would you like to do? 
  • You should prompt for input after the menu is printed. Review Media:JavaIOExample.java for examples of input/output
    1. Add import java.io.*; at the very top
    2. Add private static BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) ); before main()
    3. Add throws IOException so that main() reads like public static void main(String [] args) throws IOException
    4. You may now use stdin.readLine(); to read in a String
    5. To compare Strings, use .equals() like so: myStr.equals("a")
  • If the user inputs 'a', then print a message that says "USER SELECTED ADD"
  • If the user inputs 'f', then print a message that says "USER SELECTED FIND"
  • If the user inputs 'p', then print a message that says "USER SELECTED PRINT"
  • If the user inputs 'q', then print a message that says "USER SELECTED QUIT"

Agenda:

  • Complete AddressBook class lab assignment
  • Create the Contact remove(String fn, String ln) method for the AddressBook
    1. Using a for loop, find the Contact that matches fn and ln, and save it in a variable
    2. Once you have found the Contact, you should remember its index (location) in the array
    3. Check if the Contact was found in the array
      1. If it was found, you must use a loop to shift all the array elements down one index
      2. HINT: myContacts[i] = myContacts[i+1] //where i is a loop counter
    4. Be sure to set the last element to null (so that there isn't a duplicate Contact in the end)
      • HINT: myContacts[size-1] = null;
    5. Decrement size
    6. Return the removed Contact
  • Demo all assignments

Homework:

  • Install the Java JDK on your computer (be sure to choose your corresponding operator system)
  • Install Eclipse Classic on your computer (be sure to choose your corresponding operator system on the right)
  • Test it out, and let Mr. Bui know if you run into problems

Wednesday (9/22/10)

Warmup:

Agenda:

Monday (9/20/10)

Agenda:

  • Demo Person class lab assignment
  • Demo Car class lab assignment
  • Demo Contact class lab assignment
  • Review Arrays
  • Array practice activities
    1. Create a new Java class named ArrayPractice1. Create an array of 10 Strings (Use names of students in the room). Using a for loop, print out all the Strings in the array.
    2. Create a new Java class named ArrayPractice2. Create an array of 10 integers (make a bunch of numbers up). Using a for loop and an if statement, print print out only numbers greater than 10.
    3. Create a new Java class named ArrayPractice3. Create an array of 10 integers. Using a for loop, calculate the sum and average.
  • AddressBook class lab assignment

Homework:

  • Install the Java JDK on your computer (be sure to choose your corresponding operator system)
  • Install Eclipse Classic on your computer (be sure to choose your corresponding operator system on the right)
  • Test it out, and let Mr. Bui know if you run into problems

Thursday (9/16/10)

Warmup:

  • Be sure you have completed the Person class lab assignment
  • If you have *not* completed it, then finish it for your warmup
  • If you have already completed, then try the following warmup:
    1. Review Media:JavaIOExample.java
    2. In your Warmups project in Eclipse, create a new Java class named Warmup_9_16_10
    3. Prompt the user for an int
    4. Using an if statement, print out whether or not the user's number is positive or negative

Agenda:

Tuesday (9/14/10)

Warmup:

  • Open Eclipse
  • Create a new project named Warmups
  • Create a new Java filed name Warmup9_14_10 (be sure to include the public static void main())
  • Write a for loop that prints out all the even numbers from 100 DOWN to 0

Agenda:

Homework:

  • Install the Java JDK on your computer (be sure to choose your corresponding operator system)
  • Install Eclipse Classic on your computer (be sure to choose your corresponding operator system on the right)
  • Test it out, and let Mr. Bui know if you run into problems

Friday (9/10/10)

Warmup:

  • Cram for Software Development Quiz

Agenda:

  • Turn in any signed syllabi sheets
  • Software Development Quiz
  • Introduction to Eclipse/BlueJ/JEdit?
  • Java Review...uh oh!
    • semicolons!
    • public static void main( String [] args );
    • Hello, world! - printing / outputting to screen
    • Prompting for input
    • if statements
    • while loops
    • for loops
    • classes, attributes, setters, & getters!

Homework:

  • Install the Java JDK on your computer (be sure to choose your corresponding operator system)
  • Install Eclipse Classic on your computer (be sure to choose your corresponding operator system on the right)
  • Test it out, and let Mr. Bui know if you run into problems

Wednesday (9/8/09)

Warmup:

  • List as many different places and/or ways to obtain information during the problem analysis phase of any project

Agenda:

Tuesday (9/7/09)

Summer