Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!

Jon Avadis

Ranch Hand
+ Follow
since Jul 20, 2011
Jon likes ...
Eclipse IDE Java Windows
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jon Avadis

If i use only static variables and methods in a class, wouldnt that be very similar to a singleton "object"?
6 years ago
Its ASCII Paul

Which i guess could easily be represented by Strings, 1 String represents 1 Line of the board.

If its something like that, then your row is String1, String2 or String3, and your "column"
is Character of index '1', '3' or '5' in that string.

Im sure there are much more elegant and flexible ways, but if i'd have to do it quick&dirty,
i.e. for testing if the rest of the program works, i'd do it this way.

6 years ago
Hey guys

Im always keen on getting some new excercises, and so i tried to solve this one too. Heres
my approach, let me know what you think. I tried to get it done in a OO-design.

Class "Main"

Class "Racer"

6 years ago

Campbell Ritchie wrote:What you should do for sorting Lists is to dump the entire contents of the List into a Comparable[] array (Integer implements Comparable<Integer>, so that's all right, otherwise you would supply a Comparator), sort the array and re-create the List from the array. There is an explanation for that peculiar procedure here.

That of course defeats the whole purpose of writing a quicksort program
6 years ago

Alexander Sales wrote:i don't like the tabs on the static fields.

I dont know, I like to have my field-names start at the same point of the line (it shifted when pasting it here).

i like the high level abstractions down to the low level abstractions.
i like the method arrangements.
i like the naming conventions used.
cool usage of scanner! It's the first time i've seen it.


why NEWLINE instead of LINE_SEPARATOR? my interpretation of NEWLINE is "\n".
why use line.separator? instead of making it simple or what you really have used as delimiter "\".

Campells comment made me look at Scanner again. The default delimiter is "whitespace characters" which
includes "\n" "\r" etc. so i wouldnt even have to set it at all.
I agree that LINE_SEPARATOR would be more meaningful name.

looks like you have read Clean code by Robert Martin

I havent, but ill check it out

6 years ago

Campbell Ritchie wrote:Why is your array list static? Why are all your fields static?

I gotta admit im still confused when to use static and when not to. My reasoning here was this: Im writing a program
that sorts numbers in a txt-file, i wont need multiple instances of my fields.

Don't declare a List as ArrayList<T> but as List<T>.

Ill have to look into that.

Use spaces for indenting, not tabs.

Eclipse does that for me, i'll have to check if it can be changed in options/preferences

Why are you not creating an object and calling methods on that?
Why has your class got no constructor?

I guess thats the reason for all my static stuff. Im not thinking in objects enough yet.
I shall try and rewrite it this way

Why do you have an elements field when you could use the size() method of the List instead?

Indeed, i shall change that. I even had an additional "counter" variable before and was happy to get rid of that, but your right,
i dont need "elements".

Why are you passing a BufferedReader to the Scanner constructor rather than a File object?

I thought buffered Reading was the preferred way to go. Wont the Scanner(File) constructer use an unbuffered Filereader to
read from the file?

Why are you altering the delimiter on the Scanner rather than using its nextInt() method?

I set the delimiter explicitly to what i know the file will be delimited by. Isnt it good to be explicit like that?
I didnt know about the nextInt() method, ill replace next() with nextInt() and hasNext() with hasNextInt().

Why are you using system.out rather than System.err for an Exception message?

A bad habit of using system.out for everything i guess, will change that too.

Why have you got inconsistent indentation, with some lines containing {...}?

If i have for example a short "if" or "catch" blocks i can fit easily on one line, i tend to do it, because it look cleaner to me.
I understand its against conventions though.

You have inconsistent use of whitespace, sometimes putting a space after keywords and before (, and you are doing the same with method names and invocations.

Nicely spotted, ill try to be more consistent here.

What I am least happy about is trying to do everything in a static context rather than creating an object which does its own loading and printing (at least).

Yes. I'll try and rewrite it as Object.

I am also not happy about the return in the middle of the recursive method, but many people will disagree with me on that.

For me this was just the most obvious solution to exit the method if the given parameters are "faulty". What would you suggest to do instead?

6 years ago
Hmm im running this here on Windows XP and its completely silent, no dialog whatsoever.
I run the program, it terminates, and 2 sec later i hear the printer going off.
6 years ago
Hes wants to use it "read-only" on those machines he consideres unsafe.
6 years ago
The index '7' in there is what i needed to get MY desired printer at MY network.
('0' for me was windows XPS-Printer, '1' a PDF-Printer, and so on).
So you have to replace it with whatever index-number your printer turns out to be.
That comment i made there was misleading, sorry.

Thanks for the tipps about default printer methos Rob!

6 years ago

Shamsudeen Akanbi wrote:Can you send m̶̲̥̅̊ε̲̣̣̣ the codes that solves it Bro

As Rob verbosely pointed out: No.
But if you could explain where you have difficulties, i could give you a pointer.
6 years ago
Ok, but what part do you have questions about?
It can definitively be done in java, i just did it for fun.

Heres the plot i got (it looks distorted because " " have less width than "D")

6 years ago
I dont mind. I cant take credit for the code either, i found it and used it with minor modifications.
You might need to figure out what index the printer you want to use has on your system (line 41)
or if theres a way to always get the default-printer.

Here goes:

6 years ago
I have a program thats printing without user-dialog based on the classes


but i only know it works on Windows-Systems, not exactly sure how platform independent it is.
6 years ago

Shamsudeen Akanbi wrote:I mean how do i start inputting the values of x in my program so that the dependent variable y gets squared, i don't want to pass it in a method.

Im not sure what exactly your question is. If you know what x is, you solve the equation for y and then calculate y.
Now you have both values and can plot 1 point, for each pair for x and y.
Java can do that for sure.

About the plotting: That is very unclear. Are you supposed to plot this as a textfile, where points of the parabol are represented by the character 'D'?

6 years ago

Do you read all jar files of the given directory?
Why do you use multiple threads for this?
6 years ago