chess: (when her eyes narrow head for the hills)
I have basically given up on getting this wretched java tick done by 5pm, because currently it's just making me want to scream and hit things.

What is the way in java to:
1) Do a logical 'not' - putting a ! or 'not' in front of the statement just leads to errors, and the documentation I can find just doesn't have one - I need it for putting in front of string.equals
2) Pretend to one set of classes that you are standard input, and capture standard output (i.e. IO with System.out and System.in) to strings? (The second isn't quite as important.)
3) Force a random number generator (made with java.util.Random) to produce the same results as it did at some given time in the past.

These won't actually help me solve the problem, I think, because it's just plain broken (although I'd love to know how everyone else has got on with it, but I don't know enough first-year compscis to tell - I don't know anyone who's done it). Hopefully I'll be able to scream and hit people enough before next week to hand it in then.

Date: 2004-04-28 08:59 am (UTC)From: [identity profile] jaq.livejournal.com
I'll assume you know how to look things up in the API documentation, here's some quick pointers.

1) !myString.equals("something") should work

2) Not quite sure what you mean. System.setIn(...) and System.setOut(...) let you change the streams (if you have permission). java.io.StringReader/Writer let you treat Strings as streams.

3) Use the constructor for Random which takes a parameter long seed. A time is represented as a long.

Date: 2004-04-28 11:14 am (UTC)From: [personal profile] toothycat
toothycat: (Default)
Out of curiosity - what's the exercise?

Date: 2004-04-28 11:32 am (UTC)From: [identity profile] king-of-wrong.livejournal.com
1. Do a logical 'not' - putting a ! or 'not' in front of the statement just leads to errors

Try bracketing the expression - if you were to try (!string).equals() then it will obviously fail, so try !(string.equals()). That should work.

Failing that, if (string.equals()) {} else {...


2. Replace the calls with your own wrapper class that logs the calls through it: i.e. replace System.out.println() with IOWrapper.write().


3. Force a random number generator (made with java.util.Random) to produce the same results as it did at some given time in the past.

Store the seed value and explicitly pass this when creating the Random. new Random() uses System.currentTimeMillis() as the source for the seed value. Store this and then pass it when you create the RNG: new Random(mySeedValue).

Hope this is of some use w.r.t Tick #5!

Date: 2004-04-29 03:23 am (UTC)From: [identity profile] passage.livejournal.com
3) Store a list of psuedo-randomly chosen numbers and always feed it that?

Date: 2004-05-04 06:32 pm (UTC)From: [identity profile] marnanel.livejournal.com
You'd just be duplicating what the existing random number generator already does perfectly well with seeds, though.

Profile

chess: (Default)
Michelle Taylor

January 2025

S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 2nd, 2026 06:57 am
Powered by Dreamwidth Studios