Saturday, October 31, 2009

Sunny Day Tests

public class TestArrays {

/**
* @param args
*/
public static void main(String[] args)
{
MyArrays array1 = new MyArrays();
array1.setArray();
array1.printArray();

System.out.println();

MyArrays array2 = new MyArrays();
array2 = array1;
array2.printArray();

System.out.println();

array2.arraySet[0] = 0;
array2.arraySet[2] = 2;

array1.printArray();

System.out.println();

array2.printArray();

}

}

Sunny Day Objects

import java.util.Scanner;
public class MyArrays
{
int n;
int[] arraySet;
Scanner input = new Scanner(System.in);

public void setArray()
{
System.out.println("Enter Array Length");
n = input.nextInt();
arraySet = new int[n];
for (int i=0; i < arraySet.length; i++)
{
System.out.println("Enter Array Value for Position " + (i+1));
arraySet[i] = input.nextInt();
System.out.println("Array Position " + (i+1) + " = " + arraySet[i]);
}
}
public void printArray()
{
System.out.print('<');
for ( int i = 0; i < arraySet.length; i++ )
{
System.out.print(arraySet[i]);
if ( (i + 1) < arraySet.length ) {
System.out.print(", ");
}
}
System.out.print('>');
}

}

More sunny days in Philadelphia.

Lab 3 Arrays Exercise 1:

Aww… there isn’t a level one in the first exercise. Oh well. Looking at the project in NetBeans it looks as if I am creating the test objects for this one as well. What now? Eclipse. What are you doing? I know. I am happy we can search strings in other strings. We can also use that code along with the java.util.Arrays.toString method to parse the array into text, and that’s great, thanks, but can we please run the project package I am working in, please? Thank you. Now, umm… what were you saying?

So what happened was this. Eclipse had been distracting me by executing a program I had written for a previous lab having to do with searching text with loops and charAt. So, I went to all of this trouble to make a string something like this 1,2,3,4,5. And then I was going to parse it into an array. I think you can tell my programming background is kind of shell and batch oriented. And wouldn’t you know it: Java isn’t ksh or bash it’s Java. Fortunately for me Java makes sense, sort of, especially when you are writing it OO. I actually made this lab a lot harder than it needed to be. I still didn’t peek ahead though(yay me). It wouldn’t have been much of a challenge if I had just created new arrays and set their values with curly braces as the lab instructed, but I wanted more. I had to have an interactive application that polls you for your array length and then requests values for each place while iterating through a count from zero to the array length.

The lab of course taught the lesson that, while arrays are not primitive data types, caution should be taken to assure that in setting two separate arrays to the same starting set will propagate changes to one to them all if their values are assigned as being equal to each other rather than to the same data set.
I decided to have the methods of the object return according to type to remind myself not to leave related but functionally separate (i.e. setters and getters, ins and outs, frics and fracs, yings and yangs) statements together in a single methods. I also wrote the same functionality of statements in lines for console and window alerts. I commented out the console and affixed comments of the type mentioned in the first paragraph to both types of matching functionality. This should be sufficient to create test inputs and outputs to provide a modicum of change control as both versions could be edited by separate developers pursuing identical functional requirements thereby integrating testing. A technique like pseudocoding and then translating amenable to iterative development risk control…. but I digress.
Oklee, doke. So this weeks (next weeks) assignment has us write Java in a procedural manner and then translate that into object code. The object code be demonstrative of there being multiple companies with multiple share prices and quantities of shares outstanding. This assignment requested specific classes by name which along with a one paragraph narrative sufficed to describe the functional requirements. I could’ve made a UML diagram and worked from that but the design constraint explicated in the assignment documents were more than sufficient to hammer out methods from the procedural codes. It really was a matter of shuffling more than naming.
CS520 Module 2:

I seem to be at an impasse. I am thoroughly secure in the satisfaction of the functional requirements for this project. I am, however, tempted to explore the features and options available in eclipse and Java to shift commentary in order to have lines suffixed “//swap JOptionPane;” and “//swap.console” exchange their places behind their column delimited comment delimiters (I should check on the formatting, and maybe craft an XML schema to aid in parsing the butterfly methods and global variables into some database or another. You know what. I should probably do this… module lesson, er… object code reusability… personal library… umm… huh).

Thursday, October 29, 2009

Work while your exhausted? That's not very smart.

Exercise 3: Using Nested Loops (Advanced)

So tired must I? Tonight? Sleepy, Strings not having string methods. How did I create Strings after error they created. I woke up this morning and saw that I was doing string comparisons instead of character comparisons. I think I overcomplicated the issue. I fixed it. Now I just need to suppress the dialog for each check. I must say I am at least twenty percent smarter after a good night’s rest. I am still a little iffy on the necessity of a return statement outside of my if and loop statements that have returns, but it works so why should I complain?

Wednesday, October 28, 2009

Autocorrect

I am reading some of the help comments some of my fellow students have left. One of the ones that caught my eye had to do with "smart quotes", or error ticks not to be confused with deer ticks, which carry lime disease. Error ticks are just bugs in almost every programming language.

This one has guards on him: '“'

The suggest for preventing some of these guys had to do with changing the autocorrect options in MS Word. That reminded me of another tab in that same dialog window options thingy. I love Autocorrect. You can have so much fun with it. Mean fun, but fun anyway. I set it to replace my first name spelled in all lower case with my first name spelled in all lower case followed by the words "is a douche".

I wouldn't do that to anyone else. I wonder if a Tier 1 support technician could figure out why Microsoft Word has is making fun of a fat girl named Peggy, while she is in tears on the line. Poor, poor fat piggy. I told you it was mean. Which is why I only do it to myself.

I actually saw an episode of the office where umm... the protaganist(Mike, maybe?) confessed to writing a macro to do call Dwight a weenie or something. Betcha, disable macros occurs in a troubleshooting flowchart before autocorrect.

Of course it doesn't have to be used for nefarious purposes. Autocorrect can be used force people to stop using texty slang. This of course could be done in a mean way too though. For example you could have "ur" replaced with "you're", or "Type the @#$%ing word 'you're' you lazy @#$%ing good for nothing @#$%!" If you're feeling in the mood for little fun with cultural sensitivity, you might want to try autocorrecting "OMG" with "OMG-D, please." I always like replacing common texting slang with strings of nonsense letters. Something like replacing LOL with a brace expansion of each letter of LOL against each letter of the alphabet all concatenated together.

More puppets? Yes, more puppets. Think of the money you'll save on dry erase markers.

Well since I am supposed to be reusing the packages from the previous account lab I might as well load them. I was off feeding my virtual fish, not that you would have noticed since this is print… that gets time stamped.

I am going to skip to Tasks 2 and 3, still not peeking at level 2 or three. The last exercise only had the one level. Task 3 is dependent on the completion of Task 2, but neither requires 1, and they’re both short tasks.

Now for one. I am supposed to test the operation of some if statements. And return them. And the really wasn’t very hard. Even though I had imported the wrong packages, and I kept getting errors that were just not possible given the code I had to change for this lab. It’s a shame I was referencing a different lab. Maybe I should give the package jazzier names, make their differences really stand out.
Instead of names like lab2.exercise2.domain and lab1.exercise2.domain, I could name them things like mad.max.domain and lord.humongous.domain, or godzilla.domain and peewee.domain. Then I could printout pictures and use them in puppet shows that demonstrate the interactions between packages… and it’s a quarter till one.

Get back to work you slacker.

WJ-2752-SE6: Lab 2, Exercise 2: Using Conditional Statements in the Account Class (Level 1)

Another one? How much practice do I need with account stuff? I have a bank account, a reasonably high IQ, and an imagination. When are we going to program some stuff for proton beam ignition driver? Or a airfoil deformation controller? Or a great big demon with big old horns that has red glowing eyes and breathes fire and and shoots lightning and drops rare loot, ooh, like a helmet with big horns that grants fire protection, or something like that.

Fine, we’ll make another accounts doohickey. Like an off-the-shelf product doesn’t already blow this stupid little class out of the water. Ah, heck what do I care, it’s not like you’re paying me for this. I am only hoping someone might.

Oh, well. Carry on then.

/* Sorry sir, I almost forgot. I made a test. The outputs should be the same. Mind the comments. You look perplexed. Should I write a manual? Five or ten pages? */
public class FooBarBaz
{
public static void main(String[] args)
{
String foo;
String bar;
String baz;
int n;
n = 1; //set n to one to align 50 and 1
for (int i=50; i>0; --i) // the loop counts down but the game ticks forward... from zero, oops.
{
// System.out.println(n); // Remove comment to print n on a separate line from the ducks and geese
if (n%3==0 && !(n%3==0 && n%5==0) && !(n%3==0 && n%7==0) && !(n%3==0 && n%5==0 && n%7==0))
System.out.println("N is equal to " + n + " I is equal to " + i + " foo");
// foo, foo bar, foo bar baz, foo baz
else if (n%5==0 && !(n%5==0 && n%5==0) && !(n%5==0 && n%7==0) && !(n%3==0 && n%5==0 && n%7==0))
System.out.println("N is equal to " + n + " I is equal to " + i + " bar");
// bar, bar baz
else if (n%7==0 && !(n%7==0 && n%5==0) && !(n%3==0 && n%7==0) && !(n%3==0 && n%5==0 && n%7==0))
System.out.println("N is equal to " + n + " I is equal to " + i + " baz");
// baz & null makes 8 or 2^3, 4 remain unaccounted for.
else if (n%3==0 && n%5==0 && n%7==0)
System.out.println("N is equal to " + n + " I is equal to " + i + " foo bar baz");
// foo bar baz accounted for, 3 left, sir requesting leave. I am not required for this maximum i sir. 3*5*7 > 50, QED.
else if (n%3==0 && n%5==0)
System.out.println("N is equal to " + n + " I is equal to " + i + " foo bar");
// foo bar present and accounted for sir! c--
else if (n%3==0 && n%7==0)
System.out.println("N is equal to " + n + " I is equal to " + i + " foo baz");
// foo baz, sir bar baz is the only one unaccounted for sir!
else if (n%5==0 && n%7==0)
System.out.println("N is equal to " + n + " I is equal to " + i + " bar baz");
// bar baz reporting sir! All present and accounted for sir!
else
System.out.println("N is equal to " + n + " I is equal to " + i);
n++;
}
}

}

All that time for this?

// cute little guy isn't it?

public class DuckDuckerDuckest
{
public static void main(String[] args)
{
int n;
n = -10; //set n to one to align 50 and 1
for (int i=51; i>0; --i) // the loop counts down but the game ticks forward... from zero, oops... or -10
{
String foo;
String bar;
String baz;
foo = " ";
bar = " ";
baz = " ";
// System.out.println(n); // Remove comment to print n on a separate line from the ducks and geese
if (n%3==0)
foo = " foo ";
//
if (n%5==0)
bar = " bar ";
//
if (n%7==0)
baz = " baz ";
//
System.out.println(foo + bar + baz + n);
n++;
}
}

}

The babbling imbecile is just making up words, he is.

Weird. I am sure I have an elegant solution but now I have an unreachable code error and a dead code warning. Even weirder the hints seem to have directed me away from this elegant solution: … that still has the problem, err… umm… oh duh, else if doesn’t belong where two conditionals might be satisfied and you really don’t feel like spelling it out in Java’s version of combinatorical L… err… umm… this stuff:

(n%3==0 && !(n%3==0 && n%5==0) && !(n%3==0 && n%7==0) && !(n%3==0 && n%5==0 && n%7==0))

Which basically says n is a multiple of 3, but not 3 and 5, and not 3 and 7, and most certainly not 3 and 5 and 7. Yeah… getting rid of the else if, really simplified the code.

Is he making puppets from paperclips and Post-its?

I turned my decrement to an increment and let it run. The last line of the output was N is equal to 486276 I is equal to 486325 foo. I think I need additional if for the cases of common multiples. It may not be the most elegant method. But you can count the combinations on your fingers, so does it matter? It works!

Scrolling further down the lab assignment I find that if I left ln of the print method… Of course that puts everything on one line with adding breaks about when it increments the … you ready? The Determinator!(as opposed to the backwards running Looperator) or n as he is known to his friends.

He thinks he's figured it out.

While I was hammering my pseudo-code into Java, I came across the decision to decouple the logic count from the loop count, Huh, I am done. I suppose the test file with its while loops was just supposed to hint at the solution. I was playing with the code and noticed that 15 doesn’t print for 3 and 5 at the same time. I spoke too soon.

What's this think he's guy doing?

WJ-2752-SE6: Lab 2, Expressions and Flow Control.

I started this lab by navigating to the project in NetBeans and copying out the test class. It was in a default package (which is discouraged by the Eclipse IDE and a few other reputable Chaps) but I put it in one appropriate to my study records. I need something to validate the PDF cert I get to print out on completion of the course. I misnamed the class for this iterator class DuckDuckerDuckest. I am still having it print the three letter variables I am going to assign later, but which are not in the lab assignment. This is a print on a multiple of 3 or 5 or 7 between one and fifty.

Levels

I know what you are thinking. Why is this jerk so proud that he didn't get past level one. My Paladin is level 65 and I am not very proud.

The truth be told when I say it to myself it doesn't seem like much for me to do level one but not two or three. Well, it is, sort of. In these labs I am doing each level gets progressively easier. Level three is an exercise in cut and paste. Level two specifies in detail what you need to do. Level one says little more than here's a UML diagram make this class and when its done it should work with these other classes to do this thing.

See it really is better to be number 1. Yay me.

Watch this. He thinks he's learned something.

WJ-2752-SE6: Exercise 2, Creating Customer Accounts.

Again I am working from scratch in Eclipse. Not to worry I have NetBeans handy, and more importantly I have the lab files so I don’t need to create the classes that the lab is dependent on the preexistence of.

Done! I ran into a couple of errors here and there. I kind of fixed them too quickly to write them down or figure out what they were. One of them was a silly one where I was outputting instead of returning values. The one that took me the longest amount of time and almost frustrated me seems to be the point of the lesson.
Recall in exercise one of this same lab the equal sign we used with end and stray that changed end to stray even though we only set stray after we had end set? Well I am sure there is a reason but in this one we declared some variables for a constructor that were supposed to be passed variables from the class and to make a long story and a bunch of semantic errors short we set the constructor values to the variables instead of the variables to the constructor values. How’s that for a tricky little caveat?

I still completed level one without peeking at level two or three. I think I spell peek peak in some previous posts. Huh.

I really thought he'd give up and blame the tools.

Huzzah! I may not know the why but I know the how. So I needed to instantiate the variable point1 as a constructor value new point. Then, I needed to assign values to the point1.x and point1.y values. Ah, ha. They mean it when they say Java is strongly typed. Now in finishing the exercise which requires I set one of the three points equal to the other, I see reciprocity in the assignments as the second point to the equality reassigned affects the assignment of the first. Here is the output:

Start point is [10,10]
End point is [20,30]
Stray point is [20,30]
End point is [20,30]
Stray point is [47,50]
End point is [47,50]
Start point is [10,10]

What happened was we set stray = end. We then reassigned stray and the new values went into end. Neat trick or frustrating caveat? Only time will tell.

We'll show him!

WJ-2752-SE6: Exercise 1. Investigating Reference Assignment.

I created a separate project for WJ-2752-SE6 in Eclipse. I am thinking about going back over WJ-2751 in Eclipse before progressing to 2753. The lab actually comes with readymade projects. But I am having a go at it separately.

Our first task in this lab appears to be to create a class with an x and y integer attributes and a method called toString(). We ran into a small snag doing it from scratch. The exercise already had some classes defined. I copied them into NotePad++ and then recreated them in Eclipse in the package I am using for this exercise.
Array constants can only be used in initializers! Thank the CS department at Cornell for getting to the top of Google on that search term. What I need to do is assign the values x and y in the declaration of the point. Of course I still seem to be missing something. Opening NetBeans shows me that clearly there is something important in the IDE files that I remain ignorant of. Apparently there is something specific to the instantiation of a variable in a constructor that I am not really certain as to the meaning of.

So joyously smug...

Wednesday, October 28, 2009

I just turned in my first assignment for CS520. I am debating on whether or not to take the quiz today. I am getting a good handle on the language. That is to say my code kicks few errors back and I troubleshoot them pretty readily. Not too shabby for a beginner.

I did the labs for WJ-2751-6E in NetBeans. I installed Eclipse on the recommendation of the lecture notes for CS520. I like Eclipse. It is familiar, relatively so. It’s similar to the new DB2 Workbenches that are replacing the control center. I played around with them and they started to make a lot of sense.

I am going to do the WJ-2752-6E labs in Eclipse now. I am actually pleased with myself for having done all of the 2751 labs at level 1. I was tempted but I didn’t peak at level 2 or 3. I was tempted to peak at my labs when I did my first assignments for CS520, but I didn’t. I took a break after missing something obvious and there it was plain as day. I had commented a hypothesis for why it wasn’t working, but it was just a simple non-quotation for the values assigned to the variable. My string values in my methods were right I just assigned my variable values that were interpreted as identifiers that hadn’t been declared.

But, I digress.

Tuesday, October 27, 2009

Another little poem, perhaps

package, import, import, bugsplat@
method, method, where's the curly at
variable declared input/output strongly typed
JVM or .NET is this more than vendor hype?
Do I worry? Is SOA much more than that?

Object Oriented (OO)

I like object oriented analysis and design, and presumably that means I like object oriented programming (OOP). OOP automates a lot of best practices in procedural programming. It forces modularity. Objects are practically modules already. It forces permissions management. Attributes and methods need to be declared private or protected, and occasionally public. You didn't really need to do think about setting permissions besides execute with modules hanging out in files, but you should have.

All in all OO is a good thing. Of course the thing I like most about it is that it really lends itself to a puppet show and using the word magic. The magic inventory item walks on stage and requests to know where it is and how many friends it has there, having been asked by a talking window that can only ask such things when it calls itself someone who is allowed to asks such questions. The magic window itself knows that it is actually just relaying the message from someone who not only is permitted to ask such questions but knows the secret key phrase that proves they are who they claim to be. The window doesn't actually know the secret word jumble but it brings along the magic lock's grandson and he, being a magic lock of sorts himself, knows all about secret keys, but especially about secret keys his buddy the window needs to know about. I am really thinking about starting a non-profit that promotes using cartoons and puppet shows as part of a comprehensive object oriented design methodology.

Things I Know or Learned About Java

Java is a fantastic language and only tiniest bit less so since Microsoft came out with the .NET family of languages. As I understand it Sun Microsystems developed this, the first truly portable programming language, for microwaves ovens, and toasters, and refrigerators and stuff.

They didn't call it Java back when it was used to program coffee pots. What they did do back then was develop a two-stage compile process that turned the high-level language (the sort of human readable programming language) into byte-code which could be compiled specifically for the machine. This saved a lot of money programming coffee pots as each coffee pot didn't need to have the high level language compiled for it. This in turn meant that those people whose coffee fueled lifestyle had them living by the second hand could setup there coffee pots before bed and wake up to freshly brewed coffee.

Ouch, My Combinatorical Engine Hurts!

1. I love learning new things.
2. I love depth-wise tree searches, even though they are not always optimal.
3. I loved taking Math in college.
4. It felt magical to be able to predict the next lesson.
5. I love that basic principles of combinatorics are the reasons for 2, 4, and by extension of 4, a part of the reason for 3.
6. I am not too fond of being reminded of that Socratic maxim to acknowledge how little you by the crushing breadth of the tiniest area of a specific discipline.
7. I love that those sort of crushing breadths might someday be tamed by a team of topologists, educators, and two-banana code monkeys.
8. Of course if that works out I going to need to extract me some monkey brains and get to work applying n-space concepts to data management.
9. Ouch, my combinatorical engine has requested more depth probing threads than I can provide without my vision blurring and my fingers refusing to type.

Why Coffee Cups?

Yesterday, my ACM 1-Year Anniversary Alan Turing coffee mug came in the mail. Yesterday, I also started programming in Java for CS520. Subsequently, I opened CoffeeCup HTML editor for this first time in a year. I had an Applet to write. Of course, I didn't need to write the HTML as Eclipse has an Applet viewer.

These coincidences and an article I read, on some career website that isn't paying for a plug, compelled me to start a new blog. I also wrote a poem. I don't know if it qualifies for honorable mention anywhere, but a poem I wrote about the joy inherent in understanding reality in terms of wave-particle hyper-finite matrices did. I don't know what to call it so I am naming it after this article.


Why Coffee Cups?

There are cups o' coffee three
Count them all 0,1,and 2
Monday brought big mail for me
At ACM a whole year is through
Renew though it cost me a bit
Started Java in Fall two
HyperText cup counts to edit
Self-cert courses got them too