logo Sign In

Code Wars: Return of the java

Author
Time
I've heard it said that star wars junkies and forum folk may talk a lot about technical stuff, but when it comes down to it, they really don't know anything. Let's prove them wrong. Post some code and see if the other's can tell what it does *without* plugging it in and running it.

I'll start: anyone dare to take me on?

public boolean ****(String fileName)
{
resetDataBase();

TextInputFile f;
f = new TextInputFile (fileName);

while ( !f.eof() )
{
String localFirstName = f.readLine ();
String localLastName = f.readLine();
String localGender = f.readLine();
String localAnime = f.readLine();
String localPublisher = f.readLine();
f.readLine();

Character aSingleChar = new Character(localFirstName, localLastName,
localGender, localAnime, localPublisher);

insertSingleChar (aSingleChar);
}//End while

f.close ();

if (numChar > 0)
return true;

else
return false;
}// End ***** ()

edit:// there were spoilers...
gtfo
Author
Time
Well, this method (called *****, which the compiler will not accept) will:

Call a resetDataBase void method, with no arguments. I asume it... resets the data base.

Create a new TextInputFile class, passing the file name as argument, and I asume it has all the bufferedwriter classes inside it.

While we didn't reach the end of the input file (btw it should be an OUTPUT file, you're READING it)...
...read a whole bunch of strings, each of these in a separated line.
...create a Character class passing an incorrect number of arguments (the lines read), which would throw an exception, BUT... I'll assume you overrided that constructor and created one of your own.
... and you insert this Character object by caling an unespecified "insertSingleChar" method, I'm not sure what it does.

Then you close the file, good call my young padawan.

If the integer variable numChar is bigger than zero, the method will return true. Unfortunally this will throw an nullPointerExecption, as this variable was not declared, alocated, and was never incremented. I'm assuming it's global, for some creepy reason.

Else... it returns false.

Ok, it's a method that's supposed to read a file and save it into a database, and if it reads nothing, it returns false, returning true otherwise. Unfortunally, for the reasons I have mentioned above, it wont work.


I'll post a link about how to make obscure, confusing code so that no one knows what's supposed to do, and no one can change it. It's hilarious, for those who know how to program.
“Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is tell them they are being attacked and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same in any country.” — Nazi Reich Marshal Hermann Goering
Author
Time
Your force sight is impressive....

The code was taken from a much larger program. Hence all the nasty global variables.

It was titled ***** because the name of method kind of gave it away.

The method opens an array. Thus making the insertSingleChar[acter] self explanatory.

gtfo
Author
Time
Quote

Originally posted by: Shimraa
what the null pointer bit again.


If that variable wasn't declared anywhere, then the compiler itself would stop and complain about this. If it has been declared, but not set any value, two things could happen: the compiler could get that thet variable was null and complain, or I belive it would throw a nullPointerException, since that variable is pointing to an unlocated memory area.

It has been a while since I've stoped programing in Java, so, I might be wrong on the exception thrown.

Here's a challenge for you: create a function in any coding that gets 3 numbers and orders then, but without using IF.
“Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is tell them they are being attacked and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same in any country.” — Nazi Reich Marshal Hermann Goering
Author
Time
yous could just use switch couldnt you.
Author
Time
boogie ooga pookabeeji eck pojo

ingjapoji lumpakita mooju reecky loppor
poojoo loo foo nee

ecky ecky ecky pthang loopboing waampo ni

jeckooo paaaaaaaeeeee



Hehehe, I win.

My stance on revising fan edits.

Author
Time
Quote

Originally posted by: Shimraa
yous could just use switch couldnt you.


No, you can't use comparison of any kind. Some people tried to cheat by transforming a while statement into an if:

if(boolvar){
dostuff();
}

into

temp = true
while(boolvar && temp){
dostuff();
temp = false;
}

You can't do that either.

And Hal 9000, what kind of programing language is that? The binary language of a moister vaporator? Bocce? A primitive dialect from Endor moons?
“Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is tell them they are being attacked and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same in any country.” — Nazi Reich Marshal Hermann Goering
Author
Time
Quote

Originally posted by: Hal 9000
boogie ooga pookabeeji eck pojo

ingjapoji lumpakita mooju reecky loppor
poojoo loo foo nee

ecky ecky ecky pthang loopboing waampo ni

jeckooo paaaaaaaeeeee



Hehehe, I win.


just leave ok this thread has a secret use.