Algorithms and OOD (CSC 207 2014S) : EBoards

CSC 207 2014S: Extra Session, Week 12


Overview

Questions and Answers

If our awesome audio GUI requires library files, (a) How do we indicate that to the reader? and (b) Why would anyone even bother to compete with us?

(a) Put it in the README, along with a link as to what needs to be downloaded.

(b) Awesome is in the eye (ear?) of the beholder.

Suppose we have a working parser. Can we add MVC for only one feature?

Sure.

Tell me about these weird BufferedReader thuingsymuhbobs. BufferedReaders take readers and add a Buffer. When we have an error, we'd like to be able to show you the error. How do we make it, given that we can only mark the place and move forward?

You are correct that marking seems to be the only way to rewind. When you mark and choose a big size, it allocates that much memory.

Another alternative (I think): If you are starting with something else (a file, a string, etc.), you could keep track of how far you've read, build a new BufferedReader, and then read again from the beginning.

You could choose a maximum line length (e.g., 2048 characters) and set a mark at the beginning of each line.

How do we put an array into heap order in place?

Invariant

 perm of orig
   heap     |  ????
+--+--+--+--+--+--+--+--+
|  |  |  |  |  |  |  |  |
+--+--+--+--+--+--+--+--+
            |
            i

Initially

+--+--+--+--+--+--+--+--+
|  |  |  |  |  |  |  |  |
+--+--+--+--+--+--+--+--+
|
i

One step. From

   heap     |  ????
+--+--+--+--+--+--+--+--+
|  |  |  |  |  |  |  |  |
+--+--+--+--+--+--+--+--+
            |
            i

To

   heap     |  |  ????
+--+--+--+--+--+--+--+--+
|  |  |  |  |??|  |  |  |
+--+--+--+--+--+--+--+--+
               |
               i

Goal

   heap        |  ????
+--+--+--+--+--+--+--+--+
|  |  |  |  |  |  |  |  |
+--+--+--+--+--+--+--+--+
               |
               i

Strategy:

Code

for (int i = 0; i < vals.length; i++)
  { 
    Heap.swapUp(vals, i, order);
  } // for i

What are we doing on Friday?

Studying dynamic programming, a really cool algorithmic design strategy.

It's a generalization of one of the strategies for writing the Fibonacci function.

Now that you've come back from the Work/Life Balance Town Hall, are you really going to give us another homework assignment before the exam?

Nope. But you do have to prepare your presentation for Monday.

Exam? What exam?

3.

Talk to me about privacy in Java

private - only members of this class. Use when you don't see a reason for objects in other classes to use it, or when it's particularly dangerous that objects in other classes to use it. Provides the best encapsulation.

Some programmers believe that an object should have private fields and provide getters and setters for clarity.

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.