Wouter Hermans

Greenhorn
+ Follow
since Oct 16, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Wouter Hermans

Rob Spoor wrote:Instead of reusing the code, can't you extend / encapsulate the existing validation class(es)?



(Sorry for the late reply)

The subnet mask code extends my IP class and reuses the bulk of its code, but the rules for subnets are slightly different.

As for the binary suggestion, that definitely seems like a good idea. Thanks.
13 years ago
I'm working on some code that handles IPs entered as strings and stored as arraylists of integers. That part of the code is up and running.

Now I want to be able to enter subnet masks. This re-uses most of the code, but requires some extra validation (since only a few addresses are valid as subnet masks - see here). However, I'm not sure how to handle this since subnet masks follow some very specific rules.

Plan B is to just check against all valid subnet masks but that seems clumsy. Has anyone else had this problem before? Can anyone point me in the right direction to solve this?
13 years ago
It's running fine now. Thanks to everyone who helped out!
14 years ago
I have something similar (a simple isValid(a,b)), I just wondered whether there was an 'official' function for it. It didn't occur to me too look into enumeration, it's not something we've covered so far in class.





14 years ago


What does this do, if you don't mind me asking?

EDIT: and what is the function of the 'break' in the if-clause?

EDIT2, last one I promise: is isWithingBounds() a custom function or can I import it? Google isn't helping.

Thanks for the help so far
14 years ago
Hey,

I'm trying to make a simple noughts-and-crosses game using a 5x5 grid (String[][]; I considered ArrayLists based on my last topic but will leave those alone for now), and am now trying to write the code that checks whether the last move made a row of three noughts or three crosses (which of these two isn't important at the moment; I just need to know if there are three adjacent identical characters). But I'm having a hard time coming up with an elegant way to do the check. The options I've thought of so far are:

- Check the whole board each time. Pro: easy to code using for-loops; con: hugely wasteful.

- Starting from the last character entered, check in all directions to see if it completes a line of three identical characters. Pro: slightly less wasteful; con: code looks like this:



- Or something else

What's the best way to go about this?
14 years ago

Can you show us how you are trying to create your array?





Looks silly in retrospect, doesn't it?

Your code works like a charm - for some reason I had the idea in my head that I needed to declare the size of the board in the variables up top.
14 years ago
Hey all,

Let's say I want to make a grid of x length on each side (like, say, a chessboard), in its own class. I don't know yet how long the grid has to be on each side - that'll depend on user input. I do know that once created the grid will keep its size.

I'd like to know if it's possible to do this as an array of arrays. If the size of the grid is known beforehand it's easy enough (Array[length][length]), but whenever I try to make a constructor that takes the length variable from another class, it complains that I can't use a dynamic reference to something static. Fair enough - but is there a way around this?

The other alternative I know of is to make an ArrayList, but there I run into the problem that I can't seem to wrap my head around creating an ArrayList of ArrayLists through a for-loop.
14 years ago
Thanks, that got the job done!

Here's the code so far; it works, but it probably needs some cleaning.



The prompt asks you to type a question. q prints "have a nice day" in Dutch (when I first tried the do... while, typing q printed a random prediction before quitting, so I added an if...else to replace it with something more proper).

EDIT: sorry, broke the formatting there.
14 years ago
Hi all,

I made a little Magic 8Ball program which runs okay - it asks for input, then displays a random result from an array of responses (like the real thing, basically). I'm now trying to expand it so it keeps taking input and prints responses until the user types "q". To do this I'm using a While which checks if the input String is not equal to q, so:

!String1.equals(String2)

But this throws an error saying blabla can't be resolved (blabla is the input from the scanner):



Spot the newbie error and help a poor lost soul.
14 years ago
Thanks for the info. I hadn't been using arrays, but I'm reading up on them now
14 years ago
% gets you the remainder of a division. In this case, a number is odd when the remainder is not zero when you divide it by two.
14 years ago
Hello everyone. First time poster, long-ti just started to read this place after seeing it in an O'Reilly book.

I'm taking my first Java lessons. To get some practice I've been trying to make my Very First Application (that isn't retyped word-for-word from a coursebook) but I may have skipped ahead farther than I can handle.

My goal is to make a program that, when run, prints my next class to a command prompt, along with the room number and start/end time of the class. The way I've been doing this is:

- Make a class Interface creates all the Course objects and handles printing the result
- Make a class Course with the name, start time, end time, day of week and room of the course as variables
- Import the calendar function, make a new calendar object, and get the day of the week from it
- ?
- Profit!

I'm having trouble tying it all together though, and the more I think about it the more I think I may be going about the whole thing backwards. For instance, I input the data for each course as a series of strings, but that seems like a roundabout way of doing things - I've been looking for a way of importing the variables from a plain text file, so I just have to swap that out next semester when the courses change, but can't find how to do it. Moreover, I can't seem to figure out how to compare the current date and time to the one listed for each object in Course (that is, I'd want a method that goes through the list of courses and finds the next one that matches both the current date and the current time, but it seems I can only manage to check one specific object at a time. I doubt I'm supposed to copy the code for that one check for all 15-odd objects of the same class).

I'm not looking for a full solution, but some pointers to get me started, or even just a general idea of the best way to go about this would be awfully handy.
14 years ago