7,116 Posted Topics

Member Avatar for noobjavacoder

Create the random data run the sort and see how long it takes now run the sort again - this time the data will already be sorted - and see how much quicker that is

Member Avatar for JamesCherrill
0
248
Member Avatar for Trevor_5
Member Avatar for kayleigh0411

[edit] ; see invisal's post below for a better explanation of loop problem 100000.0 is a double constant, so the aithmetic is done in double precision, then you assign it to a float and potetially loose precision. Nowdays there's no real reason to use float ever - the precision is …

Member Avatar for JamesCherrill
0
2K
Member Avatar for LibraryCode

One way to parse lines like that is to use String's `split` method with a one-or-more-blanks regex as the delimiter

Member Avatar for JamesCherrill
0
262
Member Avatar for Doogledude123

Do you mean stuff like this (class name changed, comments deleted) to make it less obvious) public class QQQ<E> extends Vector<E> { private static final long serialVersionUID = -1859832140413652455L; private Comparator<E> c; public QQQ(Comparator<E> c) { this.c = c; } public QQQ() { // no comparator: behaves like Vector c …

Member Avatar for JamesCherrill
0
150
Member Avatar for cool_zephyr

Welcome to Java 8! That code seems to have acumulated some extra code, presumably from trial-and-error. I took your code, added a litte constructor to Order, and set up some test data like this List<List<Order>> list = new ArrayList<>(); List<Order> list1 = new ArrayList<>(); List<Order> list2 = new ArrayList<>(); list1.add(new …

Member Avatar for cool_zephyr
0
260
Member Avatar for muthu1802

16 bytes is 16 bytes. How you read them depends on what they represent and what you want to do with them. What are these bytes? Are they a signed, big-endian 16 byte integer value, or what? Knowing where they come from may help.

Member Avatar for JamesCherrill
0
219
Member Avatar for Violet_82

I don't have a JDK here, but if I remember right you are setting the weights to 1 for the text areas and 0 for the buttons, so all the available space is allocated to the areas

Member Avatar for Violet_82
0
1K
Member Avatar for divinity02

If you simply take every block of code iside those loops/ifs that is more than 3 lines long and put those in separate well-named methods then you will be able to see your overall logic flow properly

Member Avatar for JamesCherrill
0
278
Member Avatar for LibraryCode

Yes, but tag it UML as well. (I'm a huge fan of sequence diagrams as a tool for allocating responsibilities to classes, especially as a group activity around a whiteboard).

Member Avatar for JamesCherrill
0
302
Member Avatar for nadiam

That's how arrays work! You have to know the size to create the array. Java comes with things called Lists, that you can create with no entries, then add as many entries as you want. They automatically expand and contract to fit the data. That's what you would normally use …

Member Avatar for JamesCherrill
0
165
Member Avatar for Asmat_1

Not a character array! Split gives you an array of Strings, each containing one word, which is exactly what this project needs.

Member Avatar for Taywin
0
484
Member Avatar for gavriela

what exactly happens when you try to execute it? Do you get any error messages? If you start your main method with a println does that print? If you print the value of n just after line 9 what does that show?

Member Avatar for stultuske
0
5K
Member Avatar for nitin1

It's your choice. Checked means that any method that calls your method had to deal with the exception somehow. Unchecked means the calling method doesn't need to do anything, but if you do throw the exception then expect the application to crash. Which you chose depends on how likely the …

Member Avatar for JamesCherrill
0
230
Member Avatar for Violet_82

Anonymous classes are good if they are small, but if they are more than few lines the code gets hard to read, in which case a named inner class is better. (See how I avoided mentioning lambdas there?).

Member Avatar for Violet_82
0
603
Member Avatar for katie6580

Hi Rahul If you do chose to fix people's homework before them then please take the time to explain what you have changed and why you changed it as you did. Otherwise how will they learn?

Member Avatar for Rahul47
0
178
Member Avatar for Trevor_5

Use a Scanner to read the users input. If you read a single char you can compare it in an if test, but you need quotes round the constant, eg char in = ... If (in == 'K') ...

Member Avatar for JamesCherrill
0
319
Member Avatar for noobjavacoder

You are supposed to read everything in once at the start of the program. Once it's all in the hash maps you can use their get methods to search them and retrieve the requested results for as many requests as you want.

Member Avatar for JamesCherrill
0
384
Member Avatar for katie6580

Write file seems to be doing some ordering, despite the instructions. Read file seems a bit convoluted. If you can assume that the file does just contain ints then you can read it as strings, split that, then convert to ints. Alternatively ( which I would prefer) create an int …

Member Avatar for JamesCherrill
0
298
Member Avatar for Saboor880
Member Avatar for Violet_82

You can just paste the code in Code tags as part of your post. Experience shows that most people won't bother/dare to open a file attachment anyway.

Member Avatar for Violet_82
0
666
Member Avatar for Bartosz

Seems like the server is running on a machine that does not have that class in its classpath

Member Avatar for JamesCherrill
0
303
Member Avatar for Doogledude123

Never used it myself. GridBagLayout does everything I need, and I have a strong dislike of using third-party anythings unless I have to.

Member Avatar for JamesCherrill
0
127
Member Avatar for Liam_4

FYI: That little pattern on lines13-17 is so common that Java 8 Map has a new `getOrDefault` method to make it simpler. values.put(i, values.getOrDefault(i, 0) +1);

Member Avatar for JamesCherrill
0
142
Member Avatar for noobjavacoder

A binary search partitions top/bottom halfs, then does the same for the appropriate half and continues until it's found the result. That is a recursive algorithm. It would be natural to implement that with recursive code. However, it's possible to write the code without using recursion, ie an iterative version, …

Member Avatar for invisal
0
1K
Member Avatar for Von_1

2 times 3 is 2+2+2 5 times 4 is 5+5+5+5 see a pattern? see how that can be implemented with a loop?

Member Avatar for rproffitt
0
292
Member Avatar for kouty
Member Avatar for Saboor880

Have you bothered to Google, or did you think it was OK to just come here and demand that someone does it for you?

Member Avatar for jwenting
-1
130
Member Avatar for Mohamed_26

Now you have the Method object you can call it by using Method's `invoke`

Member Avatar for JamesCherrill
0
269
Member Avatar for loserspearl

It's a standard feature of the Java API, See https://docs.oracle.com/javase/tutorial/essential/io/walk.html

Member Avatar for JamesCherrill
0
427
Member Avatar for Adhya_1

DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there.

Member Avatar for Lucaci Andrew
0
259
Member Avatar for divinity02

He's right. Think about it. What is the result of` 5/100 `in integer arithmetic?

Member Avatar for ObSys
0
200
Member Avatar for kavinsac

Most bad web sites are not bad because of some technical failure, they are bad because they don't do what the user wants or expects. Learning PHP or whatever is not hard - just takes a bit of time and effort. IMHO the key skill is being able to see …

Member Avatar for diafol
0
573
Member Avatar for divinity02

Copuld be a while or a do/while. Sometimes that's just a question of preference. Try coding both and see which gives the simplest code in your specific application.

Member Avatar for JamesCherrill
0
372
Member Avatar for Niana

It will work if you override toString correctly. Check that tyour method signature is correct, ie @Override public String toString() { return <some String expression>; }

Member Avatar for JamesCherrill
0
153
Member Avatar for Niana

` RegistrationDetails registrationDetails = new RegistrationDetails(name);` creates a new instance, and initialises the `name` field, but ` RegistrationDetails registrationDetails = new RegistrationDetails();` creates a new instance and leaves the name field uninitialised (null) The fix is to call getName() using the same instance that you created with a name

Member Avatar for Niana
0
2K
Member Avatar for LibraryCode

Use the JTextField's setText method to display the clicked count. You can do that as part of your jButtonScanActionPerformed method

Member Avatar for LibraryCode
0
268
Member Avatar for Violet_82

Looks reasonable to me - except I don't see why you have a panel (line 5) with only one thing in it - just add the text area directly. For the event handlers on those keys you will DEFINITELY want to use the parametised handler technique from your previous project. …

Member Avatar for Violet_82
0
5K
Member Avatar for libreriaeben
Member Avatar for JamesCherrill
0
151
Member Avatar for Bobbyj245

OK Bobby. You posted an entire project requirement doc (I hope you own the copyright to that!). Why? What response do you expect?

Member Avatar for stultuske
-2
579
Member Avatar for efe.osato.5
Member Avatar for Taywin
0
239
Member Avatar for Doogledude123

IF you really do have a lot of drawing that is repeated without being changed and if that is consuming a significant amout of resources, then yes, there MAY be an advantage in pre-rendering it. If so, just create a `BufferedImage`, and call its `createGraphics()` to get a `Graphics2D` that …

Member Avatar for JamesCherrill
0
293
Member Avatar for Bartosz

First, some notes on your question: You can't assign a method to an ordinary variable; you assign the result of calling that ethod. You can't call variables, just methods. The code you posted is not a constructor, it's jst an instance variable with an initialiser. Anyway... The Calculation `a` is …

Member Avatar for JamesCherrill
0
469
Member Avatar for divinity02
Member Avatar for LukeJWhitworth
Member Avatar for nlanka

If you tage your topic "Java" then it will be seen by many more Java experts who can help you.

Member Avatar for nlanka
0
180
Member Avatar for Bartosz

"It doesn't work" tells us nothing. Would you take your car into the workshop and just say "there's something wrong with it" and expect the mechanic to fix it? Did it compile? Was there an error message? Did the output differ from what you expected, if so in what way …

Member Avatar for Taywin
0
287
Member Avatar for sirlink99

Without actual code one can only make wild guesses, for example: When you copy the populations is that a shallow or a deep copy? Maybe its a shallow copy and subsequent changes to members are affecting both copies?

Member Avatar for sirlink99
0
237
Member Avatar for Jack_11

I would also avoid that tutorial site. Seems to have been written by someone whith limited knowledge and no experience of Java. Eg One almost the first page I looked at I found: variable names like `email_address1` use of `Boolean` rather than `boolean` and (where isMatch is a Boolean)... `if …

Member Avatar for Violet_82
0
395
Member Avatar for Doogledude123

Agreed. BufferedImage was OK as it was, so there was no need to replace it. It's still the one to use.

Member Avatar for JamesCherrill
0
150

The End.