PDA

View Full Version : OT: Java



Sharky
04-16-2002, 06:24 PM
That's right kids, today is java day! It's 2:18amin teh pc labs, i'm alone, and stuck. So if anyone has some java skills and can lend me a hand - please let me know. I have to hand this fu.cker in, in a few hours (in mornin).

I'll just go right ahead and come out with the problem.

I've written a program that encrypts and decrypts a text message inputted in the command line. Now i need to write a command line app using preused clas to perfom the following:

a) encrypt: a specified input files and output it to another specified file using a specified key.

b) Decrypt a specified input files an doutput it it to another specified file using a specified key.

The task to be performed, the key to be sed and the i/o file smust be specified using command line args.

i know i gotta use the filewriter code but i have no idea how tp implement it. This is q4 of 6. I am so stuck.

I really have no clue how to progress.

Holla

Thanks

diego
04-16-2002, 06:47 PM
its only 6:48 here, im going to eat dinner, i'l be sure to check back every so often and laugh at your progress, **** tv tonight, its sharky hour @ the LOL, club..


GoodLuck

Sharky
04-16-2002, 06:49 PM
how desperate u must be to ask for help on a kung fu forum.

joedoe
04-16-2002, 06:54 PM
Sharky, which part are you having trouble with? Getting the command line arguments? Or the writing to a file?

Sharky
04-16-2002, 06:58 PM
both man.

this is the code of the question b4 hand that i must edit - it calls CaesarCipher.java where the methods are etc.

public class CaesarApp {
public static void main( String[] args ) {
int key = 3;
CaesarCipher jim = new CaesarCipher( key );
String message = jim.encrypt ( args[0] );
System.out.println(message);
}
}



now, i know this much code abou twriting to files:

FileWriter writer = new FileWriter( "output.txt" );
PrintWriter out = new PrintWriter( writer );

out.print(SOMETHING);
out.close();


now what? how do i use those 2 things to do what i want to do?

my problem is that i haven't learnt the basics of java properly.

cheers

joedoe
04-16-2002, 07:13 PM
public class CaesarApp {
public static void main( String[] args ) {
int key = 3;
CaesarCipher jim = new CaesarCipher( key );
String message = jim.encrypt ( args[0] );
System.out.println(message);
}
}

OK. The guys are telling me that you receive the command line arguments (file name, key, and action in this case) through the args argument of the main method. args[0] is the first argument, args[1] the second and so on. How you handle which argumement means what is up to you I guess.

As for file writing, I have been told there are 2 ways to do it. One is the filewriter classes, and that writes a stuff to a file. The other way is to treat the file as a stream (like C/C++ does).

I will see if I can get more detail for you.

Sharky
04-16-2002, 07:15 PM
Thanks joe, thanks dude.

"....you receive the command line arguments (file name, key, and action in this case) through the args argument of the main method. args[0] is the first argument, args[1] the second and so on. How you handle which argumement means what is up to you I guess. "

yeah... i er... dunno how to do this :mad: :(

Sharky
04-16-2002, 07:35 PM
:(

diego
04-16-2002, 07:40 PM
:(

Sharky
04-16-2002, 07:43 PM
i've done 50% of it. 40% is a pass. Hopefully it'll be enough.

Not exactly reaching for the stars though *heh*.

's not like i ain't been workin. it's quarter to 4... might go home... had 3 hours sleep last night, got up at 9am yesterday. good shiat.

diego
04-16-2002, 07:47 PM
shoulda saved the loans and got your good enough diploma, hope you make it" looks back to boys covers mouth in whisper and points"








loser:cool:



you been stressed tho eh in your courses, every other month something else happens to you for our enjoyment?/concern!.
:confused:

Sharky
04-16-2002, 07:49 PM
yeah it's been an eventful year man.

muhfukkas keep TESTIN ME WHUT WHUT WHUT.

red_fists
04-16-2002, 07:51 PM
40% pass, yikes that is low.

Sharky
04-16-2002, 07:53 PM
gives u an indication of the difficulty level man

red_fists
04-16-2002, 07:57 PM
Sorry, not too glued myself on Java.

Give me the problem in C, C++, COBOL (74 & 85), Assembler H, Natural or PL/1 and I could help.

:( :(

Sharky
04-16-2002, 08:12 PM
hometime kids. i'll get an hrs sleep max :D

i'll check this site when i get home, so if anyone can help, please say.

cheers

night.

joedoe
04-16-2002, 08:36 PM
Sorry Sharky, had to duck out for a while.

With the arguments, you access them in order that they are input on the command line. So if your program is called "Sharky.exe" and you command line is like:

Sharky.exe C:\output.txt decrypt 3

then args[0] would be 'C:\output.txt'
args[1] would be decrypt
and args[2] would be 3

You then use those values as required in the rest of your program. The arguments are passed into the program based on spaces between words. If for example, you have spaces in the file path, you may need to specify it using " around the path otherwise you will get the path broken up into seperate members of the args array. Usually I would put those values into either local variables or into class member variables.

In this case, you are expecting your arguments to be in a particular order. If you want to allow the user to specify which arguments are which, you will need to parse the arguments according to some flag structure. For example:

Sharky.exe -f C:\output.txt -a decrypt -k 3
or
Sharky.exe -file C:\output.txt -action decrypt -key 3
or
Sharky.exe file:C:\output.txt action:decrypt key:3

depending on how you want to handle the arguments.

My advice is to keep it simple for now and expect the arguments in a particular order.

I will see what I can do with the file writing stuff.

Sharky
04-16-2002, 08:55 PM
at home now, back with the beasty insects.

check ur pm bandit! my problem is actually putting the arguments into code!

Kumkuat
04-16-2002, 09:02 PM
Difficulty? What class is this? advanced compilers? Look at the api.

Sharky
04-16-2002, 09:04 PM
apparently there is loads of stuff in the api for help yes.

it's the fact that i don't have i don't have the basics kumkuat - and can't even arrange these arguments!

joedoe
04-16-2002, 09:10 PM
Check your PM Sharky. I have given you some sample code.

Sharky
04-16-2002, 09:21 PM
If i wasn't already pregnant with ewallace's babies (ASP), i'd want yours :D

thanks my man :)

joedoe
04-16-2002, 09:23 PM
No problem. Happy to help. It was a good chance for me to learn a little about Java too :)

diego
04-16-2002, 10:19 PM
actually finding someone online and getting help on coursework within 6 hours on a kungfu forum:D
i wonder if this forum does what the computer in WIERD SCIENCE do; Maybe we can make ralek a women, shut the lil buggr Up!.

joedoe
04-16-2002, 10:30 PM
Well, given that it is an online forum there is likely to be a geek or two online. His chances of finding help with a programming problem aren't that bad really - just lucky this geek happened to be logged on :)

diego
04-16-2002, 10:46 PM
no wait you said it not me:)

dezhen2001
04-17-2002, 04:44 AM
Sharky: hope it all went well man :)

david

scotty1
04-17-2002, 05:49 AM
Those two posts from Sharky and Diego which just had ":( "
had me ****ing myself with laughter man.

I ****ing love this forum.

:)

diego
04-17-2002, 10:29 AM
:)

fa_jing
04-17-2002, 12:16 PM
Sharky: post your code when your finished, please! I'm learning Java too. I'm probably about where you are with it.

-FJ

Sharky
04-17-2002, 12:53 PM
ok i will, but now i want to chill. :cool:

it's a **** sight longer than what i posted :(

i also made another to be able to enter a switch that would cycle through all key's (number of letters of alphabeter that letter is shifted to) until the correct one is found, but it didn't work perfectly. I'll post later

ewallace
04-17-2002, 01:16 PM
get your ass on icq so I can send you the file for your other problem.

Sharky
04-17-2002, 01:18 PM
thanks dad!

ewallace
04-17-2002, 01:35 PM
now fetch me a beer from the fridge boy.

tanglangman
04-17-2002, 02:29 PM
Whilst we are on this subject, I have a question too...

Apparently there are 6 access modifiers which I need to know for my exam in a couple of weeks but I only know of four,

Public
Private
Protected
Package (implicit)

Does anyone know the others??

Also I'm having trouble connecting to my Oracle Database.. I've tried creating a new JDBC driver object as stated by the Oracle RDBMS, I have copied the file containing the relevant class into my directory and included it in the class path.. The compiler doesn't like it, anyone have any ideas??