chess: (when her eyes narrow head for the hills)
Michelle Taylor ([personal profile] chess) wrote2004-04-28 04:40 pm

(no subject)

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.

[identity profile] jaq.livejournal.com 2004-04-28 08:59 am (UTC)(link)
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.
toothycat: (Default)

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

[identity profile] king-of-wrong.livejournal.com 2004-04-28 11:32 am (UTC)(link)
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!

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

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