The compiler doesn’t care where you place braces, but we strongly recommend that you follow a simple rule: Line up { and }.
if (amount <= balance)
{
double newBalance = balance – amount;
balance = newBalance;
}
This scheme makes it easy to spot matching braces.
Category Archives: Uncategorized
Computer Number Systems & Assembly
Computer Number Systems
Hexadecimal Operations:
1. FEED16 – 6ACE16
2. FEED16 + 6ACE16
3. (FF16)2
4. FBE116 – A55516
5. FBE116 + A55516
6. (AA16)2
Online tutorial for multiplication.
Homework: Review concepts for tomorrow’s contest.
Computer Number Systems
Computer Number Systems
All computers – from large mainframes to hand-held micros – ultimately can do one thing: detect whether an electrical signal is “on” or “off”. Computer programs in BASIC and Pascal are converted by various pieces of systems software into sequences of bits (Binary digITs) which correspond to sequences of on/off (equivalently TRUE/FALSE or 1/0) signals. Proficiency in the binary number system is essential to understanding how a computer works.
Number Systems
AP Exam Review
AP Exam Review MC-4
#5
Elevens lab: Activity 4
Lab
Adding a Shuffle Method to the Deck Class
Introduction:
You implemented a Deck class in Activity 2. This class should be complete except for the shuffle method. You also implemented a DeckTester class that you used to test your incomplete Deck class.
In Activity 3, you implemented methods in the Shuffler class, which shuffled integers.
Now you will use what you learned about shuffling in Activity 3 to implement the Deck shuffle
method.
Exercises:
1.The file Deck.java, found in the Activity 4 Starter Code folder, is a correct solution from Activity 2. Complete the Deck class by implementing the shuffle method. Use the efficient selection shuffle algorithm from Activity 3.
Note that the Deck constructor creates the deck and then calls the shuffle method. The shuffle method also needs to reset the value of size to indicate that all of the cards can be dealt again.
2.The DeckTester.java file, found in the Activity4 Starter Code folder, provides a basic set of Deck tests. It is similar to the DeckTester class you might have written in Activity 2. Add additional code at the bottom of the main method to create a standard deck of 52 cards and test the shuffle method. You can use the Deck toString method to “see” the cards after every shuffle.
Teacher’s Comments:
Chapter 8: Merge Sort Code
public class RecursiveSorts { //----------------------------------------------------------------- // Sorts the specified array of integers using merge sort. //----------------------------------------------------------------- public static void mergeSort (int[] numbers) { doMergeSort(numbers, 0, numbers.length - 1); } //----------------------------------------------------------------- // Recursively sorts the the portion of the given array beginning // at start and ending at end. //----------------------------------------------------------------- private static void doMergeSort (int[] numbers, int start, int end) { if (start < end) { int middle = (start + end) / 2; doMergeSort (numbers, start, middle); doMergeSort (numbers, middle + 1, end); merge (numbers, start, middle, end); } } //----------------------------------------------------------------- // Merges in sorted order the two sorted subarrays // [start, middle] and [middle + 1, end]. //----------------------------------------------------------------- private static void merge (int[] numbers, int start, int middle, int end) { // This temporary array will be used to build the merged list. int[] tmp = new int[end - start + 1]; int index1 = start; int index2 = middle + 1; int indexTmp = 0; // Loop until one of the sublists is exhausted, adding the smaller // of the first elements of each sublist to the merged list. while (index1 <= middle && index2 <= end) { if (numbers[index1] <= numbers[index2]) { tmp[indexTmp] = numbers[index1]; index1++; } else { tmp[indexTmp] = numbers[index2]; index2++; } indexTmp++; } // Add to the merged list the remaining elements of whichever sublist // is not yet exhausted. while (index1 <= middle) { tmp[indexTmp] = numbers[index1]; index1++; indexTmp++; } while (index2 <= end) { tmp[indexTmp] = numbers[index2]; index2++; indexTmp++; } // Copy the merged list from tmp into numbers. for (indexTmp = 0; indexTmp < tmp.length; indexTmp++) { numbers[start + indexTmp] = tmp[indexTmp]; } } }
Chapter 8: mod sum
January 30th, 2015
Share your recursive solution to yesterday’s assigment
Modify the method that calculates the sum of the integers between 1 and N shown in this chapter. Have the new version match the following recursive definition: The sum of 1 to N is the sum of 1 to (N/2) plus the sum of (N/2 + 1) to N. Trace your solution using an N of 7.
// This method returns the sum of 1 to num public int sum (int num) { int result; if (num == 1) result = 1; else result = num + sum (num-1); return result; }
Pi Day Gallery
March 14th, 2014
PI DAY!!!
Chapter 7: Inheritance – Employee
Something is coming
Chapter 7: Inheritance – Constructor Behavior
Constructor behavior
Study the code and the output from the driver class. Use the output to make conclusions based on the following:
1. Do you see a pattern in the order in which the constructor(s) is(are) called? Clearly explain
2. What criteria does the order depend on?
3. Explain how late binding, Polymorphism has a role in the behavior.