Results 1 to 12 of 12

Thread: More Java questions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    zombologist Senior Member doc_bean's Avatar
    Join Date
    Oct 2004
    Location
    Riding Shai-Hulud
    Posts
    5,346

    Default Re: More Java questions

    And the big project has started

    We have to created a sort of inventory system for an RPG, honestly, it sounds more fun than it is....

    Okay: my current big problem : I have to store items in a backpack, it has to be possible to retrieve both the heaviest and lightest item in O(1) (so independent of the amount of items), adding and removing has to happen in at least O(log(n)) (typically a binary search is used to achieve this). The problem: in order to get the heaviest and lightest item in constant time I need to sort the items by weight, but weight isn't a unique number, I need a unique number to sort the items in an ordered way. I was thinking of using a number that is a combination of the weight (as a whole number ) and the HashCode(as the decimals), but not even the HashCode is unique


    Then there are some demands about memory management, I have no idea how to this. The game has Dukats as a currency, they're actual objects. The amount of memory needed to handle Dukats in every game has to be the same.
    I was thinking of just remembering the amount of dukats stored, with references to the static variables in Dukats (they have a constant weight and value), but interpreting the assignment it seems like they want links to the actual objects (the dukats). Any ideas ?


    Similarly, Dukats can be stored in a Purse, the amount of memory needed for storing the Dukats has to be constant for every Purse. Any ideas ?

    There still some details about heroes and monsters and potions that haven't been revealed yet, so these probably aren't my last questions. For what is supposedly a 30hour project it's friggin' huge though !
    Yes, Iraq is peaceful. Go to sleep now. - Adrian II

  2. #2

    Default Re: More Java questions

    I don't get the idea about the Dukats. Do you need to do more than just remember one value, i.e. the sum of Dukats ? Or are you trying to say that you want to store each and every single Dukat as a distinct object - which I don't see the point of, not to mention it would be horribly inefficient, and completely non-sensical (one Dukat is identical for all purposes to any other Dukat). So why would you ever need more than one Dukat object, which stores a number (which represents how "many" Dukats the holder actually has) ?

    Similarly, Dukats can be stored in a Purse, the amount of memory needed for storing the Dukats has to be constant for every Purse. Any ideas ?
    Again, I'm not sure I get it. Do you need more than 4 bytes or such to store the Dukats ?
    (4 bytes assuming 2^^32 is enough for the amount of Dukats, of course).


    For the "current big problem": I dunno, do you HAVE to come up with a unique identifier ?
    I assume you know it's okay to have collisions in hash tables...so...
    Also, the choice of the data structure that you'll use should be interesting - at a first glance, I'd say hash tables, since they're generally the most efficient ones...

    sigh, I'm afraid that instead of help you're just getting more questions here...sorry.
    Therapy helps, but screaming obscenities is cheaper.

  3. #3
    zombologist Senior Member doc_bean's Avatar
    Join Date
    Oct 2004
    Location
    Riding Shai-Hulud
    Posts
    5,346

    Default Re: More Java questions

    Quote Originally Posted by Blodrast
    I don't get the idea about the Dukats. Do you need to do more than just remember one value, i.e. the sum of Dukats ? Or are you trying to say that you want to store each and every single Dukat as a distinct object - which I don't see the point of, not to mention it would be horribly inefficient, and completely non-sensical (one Dukat is identical for all purposes to any other Dukat). So why would you ever need more than one Dukat object, which stores a number (which represents how "many" Dukats the holder actually has) ?
    I asked that question too, it's horribly contrived imho, but the way it's worded it seems like they expect us to make links to individual objects. Can you make a class that can only have a single object ?

    Again, I'm not sure I get it. Do you need more than 4 bytes or such to store the Dukats ?
    (4 bytes assuming 2^^32 is enough for the amount of Dukats, of course).
    we can choose how we implement it, but he (the professor) seems to be a big fan of the non-limited numbers, such as BigInteger. It really depends on the context which we're not getting...


    For the "current big problem": I dunno, do you HAVE to come up with a unique identifier ?
    I assume you know it's okay to have collisions in hash tables...so...
    Also, the choice of the data structure that you'll use should be interesting - at a first glance, I'd say hash tables, since they're generally the most efficient ones...
    Well, we can use any strucutre we want, but they want to be able to ask for the lightest and heaviest item in real time and to add and remove items in O(log n), I think hashmaps have near O(1) so they're defiantly okay, but I need to get the weight in there somehow...

    I'm not too experienced with ahshmaps either, we've only used them once. (did I mention I wrote my first java class 10 weeks or so ago, the current structure is over 60pages already and only halfway done )

    sigh, I'm afraid that instead of help you're just getting more questions here...sorry.
    nah, I appreciate a different view on the matter
    I wish they made what they want'ed more clear though...
    Last edited by doc_bean; 05-15-2006 at 21:47.
    Yes, Iraq is peaceful. Go to sleep now. - Adrian II

  4. #4
    German Enthusiast Member Alexanderofmacedon's Avatar
    Join Date
    Aug 2005
    Location
    Where Columbus condemned the natives
    Posts
    3,124

    Default Re: More Java questions

    System.out.println("I'm sorry, I'm not that far in Java right now.");
    System.out.println("Maybe I can help you next year.");


  5. #5

    Default Re: More Java questions

    Quote Originally Posted by doc_bean
    I asked that question too, it's horribly contrived imho, but the way it's worded it seems like they expect us to make links to individual objects. Can you make a class that can only have a single object ?
    If you mean: "Can I make a class that I only ever instantiate once ?", then the answer is most definitely yes.
    Now, we might be getting into murky territory (or maybe we're already there :D), and I honestly don't know the scope of your assignment, BUT, here's an idea. It may be totally off, since, again, I don't know if using design patterns is or is not an issue for your assignment.
    From what I remember from design patterns (which is admittedly not much), one of the classical design patterns is the Singleton - which ensures that only one instance of some class exists throughout the duration of the program.
    I'm mentioning this because, IF you are supposed to use design patterns, this may be a good candidate for a Singleton.
    If you're not dealing with design patterns at all, then ignore this.

    we can choose how we implement it, but he (the professor) seems to be a big fan of the non-limited numbers, such as BigInteger. It really depends on the context which we're not getting...
    Well, ok, then I guess you can just use BigInteger, which you already have implemented, I guess. Or, does it not have fixed storage ? Can't you ask him whether he is ok with something "large enough" (i.e., 2 ^^32, or 2^^64, etc), or does he want something that can potentially increase to accomodate numbers as large as one may desire ?
    Because I sense a contradiction here: if you want _fixed_ storage, then it can't increase, so whether it's a simple integer or some intricate crap that allows you to store numbers up to 2^xxxxxxx, but no larger than that, it's a technicality.
    But if you want to accomodate potentially ANY number, that can't be done with a fixed storage - you'd need a class that increases keeps adding storage until you can accomodate whatever large number you want.
    So, I'm a bit confused (yet again).

    Well, we can use any strucutre we want, but they want to be able to ask for the lightest and heaviest item in real time and to add and remove items in O(log n), I think hashmaps have near O(1) so they're defiantly okay, but I need to get the weight in there somehow...

    I'm not too experienced with ahshmaps either, we've only used them once. (did I mention I wrote my first java class 10 weeks or so ago, the current structure is over 60pages already and only halfway done )
    Ok, you don't have to use hashmaps. You could use a sorted array. First element would be lightest, last element would be the heaviest one. Since it's an array, well, you have O(1) access. You can also satisfy the O(log n) sorting requirement by using quicksort.

    Ok, if you only started java 10 weeks ago, then I congratulate you, you're doing very very well. Honestly.
    Btw, if you want, you can point me to the assignment text, and I'll try to take a look at it (time permitting), see if I can make more sense out of it. But really, you should ask the prof/instructor to clarify all these little things - 'cause they may well grade you on them...

    Please take all my opinions with a grain of salt, since I'm by no means a Java expert or anything, and I also don't know the exact level of detail/techniques that your assignments are supposed to fit in. I also don't even know what kind of class this is - believe me, it makes a difference whether it is a Programming 101 class, or Data Structures, or Programming Techniques and Algorithms, or the focus is on Complexity, etc, etc.
    I think you get my point - depending on which of these is the case, the focus of the assignments will be on completely different things.

    Anyway, best of luck from now on as well. If any of my drivel turns out to be any help at all, I'll be happy.
    Therapy helps, but screaming obscenities is cheaper.

  6. #6
    zombologist Senior Member doc_bean's Avatar
    Join Date
    Oct 2004
    Location
    Riding Shai-Hulud
    Posts
    5,346

    Default Re: More Java questions

    Quote Originally Posted by Blodrast
    If you mean: "Can I make a class that I only ever instantiate once ?", then the answer is most definitely yes.
    Now, we might be getting into murky territory (or maybe we're already there :D), and I honestly don't know the scope of your assignment, BUT, here's an idea. It may be totally off, since, again, I don't know if using design patterns is or is not an issue for your assignment.
    From what I remember from design patterns (which is admittedly not much), one of the classical design patterns is the Singleton - which ensures that only one instance of some class exists throughout the duration of the program.
    I'm mentioning this because, IF you are supposed to use design patterns, this may be a good candidate for a Singleton.
    If you're not dealing with design patterns at all, then ignore this.
    I'll look into this if I have the time



    Well, ok, then I guess you can just use BigInteger, which you already have implemented, I guess.
    It's a standard java class.

    Or, does it not have fixed storage ? Can't you ask him whether he is ok with something "large enough" (i.e., 2 ^^32, or 2^^64, etc), or does he want something that can potentially increase to accomodate numbers as large as one may desire ?
    Because I sense a contradiction here: if you want _fixed_ storage, then it can't increase, so whether it's a simple integer or some intricate crap that allows you to store numbers up to 2^xxxxxxx, but no larger than that, it's a technicality.
    But if you want to accomodate potentially ANY number, that can't be done with a fixed storage - you'd need a class that increases keeps adding storage until you can accomodate whatever large number you want.
    So, I'm a bit confused (yet again).
    My thoughts exactly.


    Ok, you don't have to use hashmaps. You could use a sorted array. First element would be lightest, last element would be the heaviest one. Since it's an array, well, you have O(1) access. You can also satisfy the O(log n) sorting requirement by using quicksort.
    I'll look into it, I'm was now thinking of using a binary search tree, which should also satisfy the requirements.

    Ok, if you only started java 10 weeks ago, then I congratulate you, you're doing very very well. Honestly.
    I think so too

    Btw, if you want, you can point me to the assignment text, and I'll try to take a look at it (time permitting), see if I can make more sense out of it. But really, you should ask the prof/instructor to clarify all these little things - 'cause they may well grade you on them...
    It's only available in Dutch unfortuantly, i've alrady sent 2 emails with questions, the general reply is "if it sin't specified in the assignment, you can do whatever you like, we'll grade you on the result".

    Please take all my opinions with a grain of salt, since I'm by no means a Java expert or anything, and I also don't know the exact level of detail/techniques that your assignments are supposed to fit in. I also don't even know what kind of class this is - believe me, it makes a difference whether it is a Programming 101 class, or Data Structures, or Programming Techniques and Algorithms, or the focus is on Complexity, etc, etc.
    Object Oriented Programming, it's the second java class for most people who take it iirc. The focus is mainly on using the elements of OOP, such as references, overrides, static and non static variables, instance variables etc.


    I think you get my point - depending on which of these is the case, the focus of the assignments will be on completely different things.
    Honestly, I have little idea what the focus is on, they really like well documented code though, which means I spend more time writing the docs than writing the code

    Anyway, best of luck from now on as well. If any of my drivel turns out to be any help at all, I'll be happy.
    Thanks for the help
    I'll look into a few things and see what I can do with them, of course, my time is limited so i'll just do what can be done
    Yes, Iraq is peaceful. Go to sleep now. - Adrian II

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO