Operation: Benji! The Postscript

*cough* Yes, dear readers, I promised that there would be no more Operation: Benji! posts, that I was over and done with writing about my failure programming. But! I just had to write one last one, because I just figured out how to write that SETI program. (The one that calculates the Drake Equation, not the duck one.)

See, apparently there’s this nifty class called a Scanner, which can read input from your keyboard. Say you wanted to write a program to hold a conversation with your computer* using the Scanner class. It would probably look something like this:

 

import java.util.Scanner;

public class IHaveNoLife {

public static void main(String[] args) {

                Scanner hello = new Scanner(System.in);

                System.out.print(“Enter thy name, minion: “);

                String s1 = hello.nextLine();

                System.out.println(“Greetings, puny slave of technology. I see you have found the keyboard. Well done. Anyway, your name is ” + s1 + “, isn’t it? Ho hum. You bore me, lesser being. I am going to leave now.”);

                                                                        }

 }

 

As you can probably tell from this exchange, my computer is extremely humble and submissive.

But anyway, the point is that I’ve learned how to use the Scanner class! Now I can write that SETI program! Then- well, actually, I haven’t really figured out what to do with it once it’s done. Possibly add some ducks.

 

*Actually, I suggest not doing this particular activity, because from my experience computers are extremely unstable, psychologically delicate creatures who are prone to nervous breakdowns which can only be cured by banana pudding.

Operation: Benji! The Conclusion

This, dear readers, is the final installment of the epic Operation: Benji! series. After spending part of my summer trying and failing to learn Java through Eclipse, I have come to the conclusion that my only hope is to do a headstand on my Java Programming book and hope fervently that the rules of osmosis extend to information absorption as well.

Or pay attention in my Java Programming class. That could work too.

So, with no further ado, I say to you:

public class ByeBye {

    public static void main(String[] args) {

System.out.println(“Wish me luck, and many 100-percents on all my tests!”)

                                                              }

}

Operation: Benji! Day Three

After a long break from programming, I am back and ready to immerse myself in the world of Java, as per Operation: Benji! However, the world of Java does not seem to be eager to have me immerse myself in it. Today when I opened Eclipse and started up my program, I could almost feel the computer sulking at me.

Right now I am trying to figure out my SETI program, which I recently discovered might actually be possible! See, there’s this nifty thing called InputStreamReader, which actually reads keyboard input. It’s amazing!

(Cue Aerosmith: ♫ It’s amaaaaziiing… ♫)

So I immediately created a new class, which I named SETIWouldBeProud, and appropriately public-ed and static-ed and void-ed and main-ed it, added a couple of Strings and args (the latter still reminds me of pirates), and then set about figuring out how to write the program.

Unfortunately, I am a bit hazy on how to actually implement InputStreamReader. Apparently you can’t just type it in. Apparently, you need a whole block of code just to make it work. Something about try { and throws and InputStreamReader = new InputStreamReader(System.in); – the last phrase either enables the computer to read a single character of text or invites aliens from Neptune to camp out in your backyard. It’s not clear.

Huh. Maybe I should tell SETI that their program isn’t coming isn’t coming anytime soon. But I have a nice one with ducks they might like!*

 

*See Operation: Benji! Day Two for more information.

Operation: Benji! Day Two

As it turns out, dear readers, there is a Java equivalent to raw_input. But it’s really long and ugly and, judging from Eclipse’s reaction when I put that in there, has some sort of personal feud with the compiler. So it looks like my SETI dreams aren’t coming true any longer. :(

On a brighter note, I figured out what an array is. It’s… it’s… dangit, I forgot. Hang on.

(sound of rapid page-flipping)

Ah yes. An array is something you make after public static void main(String[] args) {, which I never get tired of typing. Basically, in an array (no I’m not going to stop bolding that), you create a bunch of new objects and give them some sort of number. I think. For example, you can create an array of seven Ducks:

Duck[0] = new rubberDuck();

Duck[1] = new rubberDuck();

Duck[2] = new rubberDuck();

Duck[3] = new rubberDuck();

Duck[4] = new rubberDuck();

Duck[5] = new rubberDuck();

Duck[6] = new rubberDuck();

Which would then leave you with a heck of a lot of Ducks in your program, which would then leave you with a mostly useless piece of code. (“Hey, Mr. Drake*, sir, I couldn’t figure out how to make that program you wanted me to, but I did make this swell one with ducks!” Yeah, that’d go down well.)

So, in conclusion, dear readers, I hope this short post has been both entertaining and uninformative, because we wouldn’t want you to start actually learning things from this blog, now, would we?

Of course not.

 

*Frank Drake, one of the main minds behind SETI. I don’t think Sir Francis Drake, sixteenth-century English buccaneer, would work very well in this context.

Operation: Benji! Day One

Operation: Benji!’s commencement.

(The title, dear readers, is a reference to the nerdy British computer programmer from Mission: Impossible 4. I love that movie.)

So I decided to learn Java. I already know a tiny bit of Python, by which I mean that I know how to hold increasingly awkward pre-programmed conversations with my computer, who seems to nurse an unnatural fondness for bananas. But in order for me to succeed in my Java class next year, I must first teach myself the basics. And that’s why Operation: Benji! has commenced.

I’ve learned quite a lot, actually. I’ve learned public static void main(String[] args). I don’t know exactly what that means, but it certainly looks official enough, except the last part reminds me of pirates with strings. I’ve also learned about classes – apparently Java codes are not exempt from the No Child Left Behind policy – and loops, which for some reason call to mind those places where you try to kill yourself on roller-skates.

I also wrote a nifty program that, when you run it, takes a value x, multiplies it by 4 until it reaches 10,000, then divides it by 2 until its value goes under 20. I can’t imagine an instance where I’d actually need to use it, but there’s a certain satisfaction present in just clicking the ‘Run’ button over and over and over and over and over and over until the number 796 is firmly imprinted in my head.

Lately, I’ve been wondering if there’s a Java equivalent to Python’s raw_input. You see, I want to make a program that calculates the Drake Equation, just in case any SETI scientists knock on my door and ask me for one. Most people would probably call this scenario ‘unlikely’, but then again, most people would also call the presence of flying whales on Jupiter ‘unlikely’. (It’s not. Read Terry Deary’s Extraterrestrials).

And that, dear readers, concludes Day One of Operation: Benji! Stay tuned for Day Two’s entry. Maybe I’ll write an even more exciting program, one that involves powers and square roots.