Difference between revisions of "IB Computer Science 2"

From WLCS
Line 18: Line 18:
  
 
'''Agenda:'''
 
'''Agenda:'''
* Add a (s)ort option to your AddressBook
+
* Introduction to the Program Dossier
** In order to compare Strings:
+
** [[Media:CriterionA1_problemAnalysis.doc]]
<source lang="Java">
+
** Analyzing the Problem due Thursday (10/4/11)
if (str1.compareTo(str2) < 0)
+
** Work on your Analyzing the Problem section
{
+
* Demo SelectionSort.java
  System.out.println(str1 + " goes before " + str2);
+
* Introduction to Bubble Sort
}
+
# Initialize the front to be the top or beginning of the array
</source>
+
# Now go to the bottom/end of the array
* So inside your AddressBook, you'd have something like this:
+
# Compare the two adjacent elements to see if they are in proper sequential order
<source lang="Java">
+
## Swap the elements if they are out of order (bigger number to the left of smaller number)
if (myContacts[i].getLastName().compareTo(myContacts[j].getLastName()) < 0)
+
# Move to the next pair of adjacent elements/numbers
</source>
+
# Repeat steps 3 and 4 until the smallest number has "floated" to the top/front
 
+
# After you traverse the entire array
 
+
## Move the front so that the sorted numbers are ignored
 +
## Go back to the end of the array
 +
## Repeat steps 2 through 6 for the unsorted part of the array
 +
* [http://math.hws.edu/TMCM/java/xSortLab/ Sorting Animations]
 +
* [http://www.cs.pitt.edu/~kirk/cs1501/animations/Sort2.html More Sorting Animations]
 +
* Download [[Media:BubbleSort.java]]
 +
** Fill in the commented parts of the BubbleSort.java file. Where there is a comment, you need to write code.
 +
** Demo to Mr. Bui at the end of class
  
 
== Monday (9/24/12) ==
 
== Monday (9/24/12) ==

Revision as of 11:06, 26 September 2012

Wednesday (9/26/12)

Warmup:

  • Assume you have the following code:
a = 3
b = 5

System.out.println("a = " + a);
System.out.println("b = " + b);


//swap the values in the variables here


System.out.println("a = " + a);
System.out.println("b = " + b);

Agenda:

  • Introduction to the Program Dossier
  • Demo SelectionSort.java
  • 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

Monday (9/24/12)

  • 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

Thursday (9/20/12)

Agenda:

Friday - Tuesday (9/14/12 - 9/18/12)

Warmup:

Agenda:

Homework:

Wednesday (9/12/12)

Agenda:

  • Demo Media:CombatSimulation.java
  • Review Arrays
  • Array practice activities. Create a new Java class named ArrayPractice
    1. 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 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 an array of 10 integers. Using a for loop, calculate the sum and average.
    4. Demo ArrayPractice
  • AddressBook beginning walk-through
  • AddressBook class lab assignment

Monday (9/10/12)

Warmup:

  1. Bring up NetBeans
  2. Import your summer assignment
  3. Demo using Media:CombatSimulation.java

Agenda:

Thursday (9/6/12)

Tuesday (9/4/12)

  • Introductions
  • Name cards
  • Lab setup/config
    • Login username is your first initial and lastname (e.g. pbui)
    • Your password is your student ID number
    • Go to Apple (upper left) -> System Preferences -> Accounts -> Change Password
    • Acceptable-use policies apply in this lab!
  • Complete the Student Surveys