If you mean: "Can I make a class that I only ever instantiate once ?", then the answer is most definitely yes.Originally Posted by doc_bean
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.
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 ?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...
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).
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.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, 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.![]()
Bookmarks