I. Degrading Prime Numbers (due Jan. 17 at beginning of class)


Classes and Objects: Java

oopIn the conventional OOP language Java, a class is a collection of objects that have common properties, operations and behaviors.

A class is a combination of state (data) and behavior (methods). In OOP, a class is a data type, and objects are instances of that data type.

*classes are prototypes from which objects are created.

Example: class Human, which is a collection of all humans in the world. Humans have state, such as height, weight, and hair color. They also have behavior, such as walking, talking, eating. All of the state and behaviour of a human is encapsulated (contained) within the class human.

An object is an instance of a class.

An object can communicate with other objects using messages. An object passes a message to another object, which results in the invocation of a method. Objects then perform the actions that are required to get a response from the system.

Real world objects all share two characteristics; they all have state and behavior. One-way to begin thinking in an object oriented way is to identify the state and behaviour of real world objects.

Software objects are programmatic analogues to real-world objects. An object stores its state in fields, and it exposes its behaviors by its methods.


Here's the Program to Enter

Here's the Main program:




Primenumberhomework2 has two supporting files, one to gather the lower and upper bound, GatherData, and one to determine the sequence of primes, given that upper and lower bound, calculatePrimeNumbers:








So we have three files total, which I call "Main," "GatherData" and "calculatePrimeNumbers." Ordinarily, I will provide links to files so you don't have to type the code in but, since we are all eradicating summer rust, I want you to enter the three files and get them running using the editor of your choice (where needed, the course will support Netbeans).

Once you have it running in (more or less) pure OOP form, ruthlessly degrade it back to crude, deeply offensive, classical imperative form, with every thing in one file and everything inside Main, much as if you were doing an old Pascal or Fortran or--God forbid--an old BASIC program. No methods, just in-line code (control structures are fine). Compile it and run it, making sure you get the same output.


What to Hand In

(1) Do screen captures of both versions of the program when you have them running, illustrating the output. Do a screen capture that captures both the code and the output in one image. Email the files (in-line, one after another) of both forms of the program to crockett@augsburg.edu.

(2) Explain how the program works in both cases, in reasonable detail (1/2 page of explanation or so for each file of the OOP version, perhaps a page for the non-OOP version).

(3) Important: Using concepts from our first class meeting, explain the differences between the two versions. Why go to the bother of writing OOP versions of the program when this clearly entails more fussing and more work? This should be two pages, well written, making skilled use of the concepts. Maintain a backup of all your work, just in case Canadian terrorists steal your work in my office.





II. Two OOP Fibonacci Versions (due Jan. 24 at beginning of class)

Fibonacci art spiralling fractalIn the 12th century, Leonardo Fibonacci wrote of a simple numerical sequence that lies back behind many amazing natural phenomena, such as the turning of hurricanes and rabbits procreating prolifically. The spiral at right is known as the "Fibonacci Spiral."

Starting with 0 and 1, each new number in the sequence is simply the sum of the two prior numbers .

OOP0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, . . .

The ratio of each successive pair of numbers in the sequence approximates phi (1.618. . .) since 5 divided by 3 is 1.666 and 8 divided by 5 is 1.60. The proportions of adjacent terms begins to approach a fixed limiting value of 1.618034, a famous ratio indeed. Also known as the Golden Mean of Euclid and Aristotle, the divine proportion of Leonardo da Vinci, it is considered the most beautiful and important of quantities.

It has been rediscovered in a variety of forms, for example, in branches of mathematics and biology. It has led to important applications in computer science.

The Egyptians may have used both pi and phi in the design of Pyramids and the Greeks may have used it for the Parthenon. Phidias (500 BC--432 BC), a Greek sculptor and mathematician, studied phi and evidently applied it to the design of sculptures for the Parthenon.

Plato considered the golden section to be the most binding of all mathematical relationships and the key to the physics of the cosmos. Euclid's famed Elements referred to dividing a line at the 0.6180399 as "dividing a line in the extreme and mean ratio." This later gave rise to the use of the term mean in the golden mean.


Programs to Enter:

Fibo JavaS Fibo JavaScript

Of course, the one on the left is in Java, the one on the right, as an HTML file with embedded JavaScript, is the JavaScript equivalent. Enter both and get them running, then answer the following questions. You might want to do a little digging but give it your best shot, given your reading of the Lab, and what you know.

(1) Write several paragraphs describing how they differ, especially in terms of data typing. Why do you see no data types spelled out in the JavaScript? Why no concern about "Public" in the JS?

(2) Explain why the "feel" of the two programs is remarkably different. Which one is like a Hawaiian luau and which is like a British tea at Oxford?

(3) Important: Why does JavaScript fit more naturally with the Web and how does it (arguably) embody the movement to OOP and XP even more than Java?

Shoot for at least a page each for each of these discussions, making some use of the first week's labs.

What to Hand In

Do screen captures of both versions of the program when you have them running, illustrating the output. Hand these in, separately from your essay, but staple them together, with your name at the top. Have some fun with these!