JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How can I get this source code?

It's a learning assignment. You get the source code by writing it yourself - that's how you learn.

If you are trying to write it, and you're stuck, explain what you have done so far and what's blocking you. Someone will help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you're still interested...
Here's a little runnable demo I hacked up in Java to show how the recursive solution works:

    int[] values = {1, 2, 9, 3};
    int target = 8;

    tryValue(0, 0);

    // recursive algorithm to try all possible combinations of values and
    // multipliers that add up to the target.

    // LIFO history of steps leading to the current one...
    Deque<String> solution = new LinkedList<>();

    void tryValue(int valueIndex, int runningTotal) {

        if (valueIndex >= values.length) {
            return; // tried every value
        }

        int value = values[valueIndex]; // just for convenience
        int multiplier = 0;
        int newTotal;

        // keep trying multiples of this value until it exceeds taget...
        while ((newTotal = runningTotal + value * multiplier) <= target) {
            solution.push(multiplier + "x" + value);
            if (newTotal == target) {
                System.out.println(solution + " = " + target);
            } else {
                // try adding (multiples of) the next value....
                tryValue(valueIndex + 1, newTotal);
            }
            solution.pop();
            multiplier++;
        }

    }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I doubt that you will find an off-the-shelf solution, nor will you find an easy one.
You need to traverse a tree with nodes for each value x1, x2, x3 etc.
Looks like a recursive algorithm.
How much do you really want a solution?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A lot depends on whether you are doing a simple conversion or producing a Java equivalent program. Eg simple conversion would just use classes where a more natural Java version would use enums for Suit and Value, and a record for Card.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The one thing in this that could trip you up is that Python’s [] do not translate to Java’s [] arrays. Java arrays do not support list-like operations such as pop or append. Java’s Deque (double ended queue) class should provide all you need when the code uses more than just an indexed access.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm no Pythonista, but if I understand it correctly there's a Queue class that is designed to be thread safe for concurrent producers and consumers. That would make the code very simple (eg, producer simply sits in a loop and blocks when queue is full, consumer simply blocks until a value is available).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Time for a reality check.
Generating a pseudo random number is one multiplication, one addition, one modulo.
It’s a fast as a function can be.
You can’t make it faster by adding the overhead of storing and retrieving values. The use of sleep to synchronise around an empty pool will utterly destroy the performance when large quantities of values are needed quickly; that needs proper synchronisation which will bring its own overheads. Yes, you can potentially gain 2x performance by using two cores concurrently, but I’m pretty sure the overheads will be greater than 2x.

Pritaeas’ original suggestion was to pre-compute a pool of numbers. The o.p. Wants 75,000,000 numbers every 16 mSec. So a pre-computed pool of (say) a billion numbers (4 GB minimum) will last less than 1/4 second. After that all you have is overhead slowing things down.

The real question is why does o.p. Think he needs 75,000,000 random numbers? That’s almost certainly based on some kind of misconception, and that’s what we should be addressing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

With 5000 soldiers that should be 5000 random numbers. The 1/15000 chance requires just one random number.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Despite your variable and class names seemingly chosen to make this as hard as possible...

It looks like the server may have closed the connection before the client gets to read a whole line. You don't say whether this happens on the first word or a subsequent one. Some more debug info is needed here. eg trace every string being sent or received at both ends, trace when the loops are exited etc

mihailbog245 commented: I found the solution . First of all I didn't look carefully in text file and I put words in text file in a wrong way. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to share the exact details of the socket exception

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Googling "pin block encryption java" got me. lot of hits. Is that what you meant?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hint: Count the steps while traversing the list until encountering position p

isnt it put the method Iterable positions();?

Yes. Simply use positions() to loop through the elements incrementing an index and and test each until you find the one you want. Then return its index.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

JavaDB is just Derby, which moved from Oracle to Apache where it is still very much alive.
The most recent release was March 1st 2021 (!)
https://db.apache.org/derby/

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm trying to run VirtualBox in Ubuntu.

The full report shows that you are running WIndows 7, not Ubuntu.

(and... you are running an OS that's past end-of-life support with both the firewall and the anti-virus turned off.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why make this so complicated?

Problem: VT-x is disabled.
It;s suported by the CPU
It's supported by the motherboard
He just needs to enable it in the BIOS. Here are the instructions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

VT-x is disabled in the BIOS

Seems clear enough. Re-boot into your BIOS configuration and enable VT-x

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Q: "I want to learn first aid" A: "I suggest you start with brain surgery"
C++ is a nightnare agglomeration of everything that is difficult from every other language. Definitely not for beginners, nor (IMHO) for anyone else.
Almost any modern language would be a decent place to start. Loops and if tests are pretty universal, as is some kind of OO now.

Remember that what you need to learn to program in real life is like 10% programming language and 90% API/toolset/libraries etc. Some langauges come with a matching API library (eg Java. Swift) but others like need you the chose APIs to learn as well.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

maybe you need to flush/close the output stream explicitly?

Saboor880 commented: Thanks for your response James. I forgot to flush out the streams. I did that and now the pdf is not crashing +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The scope of a local variable declaration in a block (§14.4) is the rest of the block in which the declaration appears (Java Language Spec 6.3)

So the exibited behaviour is what the JLS requires, depending on how you see the multiple assignment, but 4.12.3 seems to clarify that

a local variable could always be regarded as being created when its local variable declaration statement is executed.

because the declaration/intialisation will be executed after the assignment to its right.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hre's another approach that IMHO is much cleaner... use the id property that's inherited by every JavaFX node.

When creating the controls set their id property to the index i
In the event handler get the node from the MouseEvent and get its id
Now you can use a single event handler, and all the info is kept in the JavaFX control where it belons.

Vin vin commented: thanks man, I forgot the setid and getid thing. this makes my project much easier to work with. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

eventhandler is a interface, so I had to implement instead of extends

That's right. Sorry about that. I'm still on Swing, so my JavaFX is a bit patchy. I just typed that code on my iPad so had no chance to run it through te compiler.
Still, glad it helped :))
JC

ps: Please mark this "solved" if you are happy with the solution for the benefit of future readers

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could use an ordinary inner class instead of the anonymous event handlers, and pass i to the constructor. Something like

class MyHandler extends Eventhandler {
  int i;
  MyHandler(int i) { this.i = i;}

   @Override
   public void handle(MouseEvent event) {
        UI_SelectionMenu.selectedTile = i;
         System.out.println(UI_SelectionMenu.selectedTile);
   }
 }

 ...

 for (int i = 0 ; i < imgArrayList.size() ; i++) {
        imgArrayList.get(i).setOnMouseClicked(new MyHandler(i));
}
Vin vin commented: james, thank you very much. btw the eventhandler is a interface, so I had to implement instead of extends. But it still helped me a lot (: +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

only God knows and they are not talking to me at the moment.

Presuming that you are using "they" as a gender-neutral pronoun, then shouldn't that be "they is not talking to me"?
It sounds so wrong, but it's logical.

If, on the other hand you are referring specifically to the Christian 3-in-1 god, then "are" could be correct.

rproffitt commented: And I didn't account for the no-diety scenario. For that, they are truly on their own. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's hard to answer this without giving the actual solution (which we prefer not to do - you learn more by working it out for yourself), but here's some pseudo-code to show how to do this

declare and initialise a counter before the main loop
inside the loop:
        each time you print a value increment the counter
        if the counter modulo 10 is zero print a newline
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 14
Suppose i is counting up in fives, i%10 is 0 every other pass ( 5, 10, 15, 20 etc) , so you get a new line every 2 passes.
You need a separate counter for the 10 items per line.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Click on "Reply to this topic" and there's a "Question Solved" slide switch at the bottom.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, that worked perfectly.

Of course it did! ;)

Glad to have helped
JC

ps: Mark Question Solved?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That could be much easier amd faster of you sorted the List (or create a sorted copy) first. Then just store every record that's equal to the previous record.

If not... have you tried changing line 5 to
for(int j = i+1; ...
... which should fix it for one duplicate, but stilll leaves a problem for multiple duplicates.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Great!
Let me know if/when that's done and I'll help you get the Listener stuff working.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. Step 1: Separate the data from the user interface - ie separate the Model from the View.
You should have a class that loads and holds the master list of Items and has public methods for adding and removing items, getting items etc. It has no UI. The windows should be passed the manager instance into their constructors so they can use it to access whatever data or functionality they need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sure. I'll get something together tomorrow. Goodnight. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can start by considering these three options to see which fits your needs best...

  1. Make it public. Very easy, but horrible violation of encapsulation
  2. Have a public method (or methods) in Sale that updates the combo box - eg addItem(Item i) removeItem(Item i). A bit more code, and it encapsulates nicely, but creates an untidy dependency between the main Item list and the Sale window.
  3. Use a Listener/Observer pattern so the Sale window adds itself as a listener to wherever the master list of Items is held. This is the best architecture - classic MVC - but the most code.
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I get that.
Although the sale window is not visible, it still exists, with all its components. So you can update the contents of its combo box at any time. So when you add or remove items you need to update the combo box immediately. Then whenever you display the sale window the combo box will be up to date.
You just need to ensure that the code where you add or remove items has access to the combo box object... there are multiple ways to do that, which we can discuss if you want.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I saw this topic briefy late last night (C.E.S.T.) and it seemed odd. Now in the morning it still seems odd. It's not at all clear what is the problem here.
Whenever you add or delete products you need to update the combo box's contents (add or remove an item, or simply re-load the whole contents). What is it about that that is causing you difficulty?

Saboor880 commented: Thanks for your response James. I have added another reply and explained the problem in detail. Kindly go through it. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

map(s -> Optional.of(s)) is transforming those objects into Optionals, correct?

Yes, but more accuratel: .map creates a new Stream from the values returned by the lambda.

There are probably other ways to do it, but this is a really obvious and easy-to-read solution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Something like this should give you enough info...

        Stream<Integer> si = Stream.of(1, 2, 3, 4, 5);
        List<Optional<Integer>> result = si.filter(i -> i < 4).
                        map(i -> Optional.of(i)).
                        collect(Collectors.toList());
        System.out.println(result);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you start to press the next key before you have fully released the previous one then the release will override the press. Maybe that's part of the problem???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Great! Well done.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if I placed the class just in v7, the error is gone and the music can play, but if the class is inside of v7.v1 then I get that error.

Then just place the class in v7! Faffing around with IDEs just a distraction from learning a language or API.

ps: putting JavaFX code in init() is generally a bad idea. The JavaFX environment is not fully ready at that time. You are much safer ignoring init()and putting everything in start(...)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like some very quiet music. (those numbers are deciBels)
While testing it will be more manageable if you have (say) 8 bands rather than 256.

I thought if I set the interval to 60, I thought it would update 60 times per second

I guessed that was the case. It's a really good example of why you should ALWAYS read the API doc for any method you're not familiar with.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

how do I see when listener is called

OK, you seem to be missing some basic understanding here. It's just like using a listener for someone pressing a button.

You have set this as a audio spectrum listener. Which means:

  • this contains a spectrumDataUpdate listener method
  • when the media is playing JavaFX will reguarly call your spectrumDataUpdate method at the interval you have requested (60 seconds!) passing it the audio spectrum data for the latest interval.
  • In your spectrumDataUpdate method you do whatever you want with that data, eg correct the magnitudes and pass it to another method that displays it

PS: You may want to set a lower interval. The default is 0.1 seconds.

pps: It's best if you reply with a new post rather than a comment because new comments don't get prioretised in the "latest posts" listing that I'm monitoring.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can’t print those values in the start method. Start runs once and is finished before the music starts playing.
You can only access the values via the spectrum listener when the listener is called.

ps: you may want to have the listener called more that once per minute ;)

Vin vin commented: how do I see when listener is called +0
rproffitt commented: The old PRINT A; A=1: issue. Why did A print? +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The last link you posted explains how to get and understand the magnitudes, so what exactly is your question?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

new Runnable(){@Override public void run() {}};

Thats one part of one way to start a new thread. Without the other part it does nothing.
You still have AnimationTimers that make no sense at all.

You are now wasting your time (and mine) by cutting and pasting code you don't understand.

Read about threads in computing.
Then read about threads in Java (see the Oracle tutorials)
Then read about threads in JavaJX
Then you will know what you need to do, and why.

There is no short cut to this. Do it properly or don't do it.

Vin vin commented: I am going to do that, sorry for wasting your time, I am going to do my very best to understand this topic. +0
rproffitt commented: Here's hoping Vin Vin will wake up soon. Elsewhere this would result in much worse. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What part of " if it's someone else's example code then no, you cannot post it here or anywhere else without the copyright owner's permission." didn't you understand?

Research the concepts and write your own code. It's the only way to learn.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you want to post code do it as part of a code block or inline ciode (icons 3 and 4 above the text input box). But if it's someone else's example code then no, you cannot post it here or anywhere else without the copyright owner's permission.
I watched about 15 secs from near the beginning and the first thing I saw was a Thread for the connect, so that's a good start. Unfortunately the way he did it is not recommended best practice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So basicly I have to find a way to unblock ui events in my program

Yes, or, more accurately, avoid blocking them in the first place. The most obvious way is start a new thread and call your waitForConnection() in that thread. Like that it can sit waiting for connections without blocking any other activity. You may need to read up on threads in general to get the concepts, but having done that it's like 1 line of code to do it in Java.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know what you mean with thread

OK, that's going to be a problem with an app like this. Threads and Threading are a fundamental topic in computing, and relate to how a program can do multiple things at the same time (eg respond to user input while waiting for a network connectin). To do two things like that at the same time required two threads. You are converting a Swing application, but Swing and JavaFX use threads in slightly different ways (see techy note below), so the code cannot always be simply tramslated.
All I can suggest is that you find a tutorial about threads on the web that matches your current level of expetise, then check out some of the web sites that explain how JavaFX uses threads.

ps: I have no idea why you are using those AnimationTimers - you do know that their handle methods will be called 60 times per second?

Techy note: A Swing app starts in the main program thread and Swing has its own thread for any UI stuff. That means you can exter a wait-for-connection in your startup code (main app thread) while UI events continue to be handled. JavaFX calls your start method on the same thread that it uses to handle UI events,so it you wait in the start method all UI events are blocked. (AnimationTimer handle methods are also queued/called on the same thread.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ like he said.

Waiting for a connection has to be done in its own thread if you want the app to respond to anything else while waiting.
Same goes for the whileChatting loop

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't have time for a full reply now (I'll try later) but the short version is:

Start with the API definitions for the distinct layers. Eg if its just MVC then define the model's API.
In multi-layer systems I would still start ith the API for the layer below the UI because that effectively defines the system's visible functionality.
This gives you a clean architecture and allows development of the layers to proceed in parallel. It also maximises the chances that the client may understand exactly what he is signing up for.

ps: rproffit: I was Principal Consultant at Easel when Jeff Sutherland et al developed Scrum based on the informal processes we were using in the field, and I remain a fan to this day. Almost anything woud be better than the traditional guaranteed-to-fail waterfall method!

rproffitt commented: Thanks for that. I should have written more about how we are somewhere in the middle of full Agile to Waterfall on the spectrum. i.e. middle of road. +15