This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I'm required to produce a Hasing Index which centers around a class(Student) which represents a student who has a name and a course.
The program needs to use 3 classes:
1. Student class Store the student details and calculates the hash index.
2. Storage class Contains an array of Student objects and uses the hash index returened from the Student object. The class should define a method which accepts an instance of the Student class to be stored into the array of Student objects.
3. MainProgram Class This class is the main program that accepts the user's input and stores the details using a storage object. The program should keep requesting input until the list of students is full. Once the list is full, the list should be displayed for the user to see.
* I need to obtain the user input using Java's JOptionPane class and the call showInputDialog method.Also there is no inheritance between the above three classes.
Could anyone please guide me on this! I'm not sure as to where I should start, how to incorporate an array that contians 24 elements etc...
In the mean-time, I have one specific thing to comment-on: -
Originally posted by Oliver Tennant:
It is not true that you must System.exit() after using JOptionPane. It is true that programs using Swing (of which JOptionPane is a part) can have a problem of failing to exit when you think they ought to do so. But System.exit() is an ugly hack of a solution to this.
The failure to exit comes about because Swing programs do not exit until all Frames/Panes are disposed. When you create a Frame/Pane giving no parent, Swing "helpfully" creates one for you. Unfortunately, this automatically-created Frame is inaccessible to you and is never disposed. Hence the application never exits.
The clean solution to this is never to create a Frame or Pane without giving a parent. Create a JFrame of your own, and use it as the parent. When it's time to exit, and you have disposed all other Frames and Panes, dispose of the extra JFrame, and the application will exit.
Something like this (untested code): -
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Joined: May 11, 2007
Perhaps I should have put this include in the post; "I don't want someone to do it for me, however I'm really struggling with this one and I simply need some assistance in terms of direction of coding the application".
I most certainly do not want anyone to submit the code and say here you go! I need to understand Java, however as I previously said I�m struggling, therefore I require some input on how best to approach this task, where I should be looking to begin etc... And things to bear in mind.
Here's a neat approach when a big problem feels overwhelming. Write some code outside the assignment to exercise the smallest part of the problem you can pick out. For example, could you make this code say "true" for each test?
Try to write one new test, then a very few lines of new "production" code. Every new test that passes is a small victory - give yourself a treat! That keeps it fun instead of sweating for hours and hours wondering if it will work. And if you get stuck, you'll have a failing test that clearly shows what you need to do ... or ask us about.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Thanks Stan, for this very sound advice, this technique has helped me plenty during coding, in the past. My thesis was based on a paper "Breaking a complex system into its subsystems' which followed a similar approach that a complex system can be simplified if you can break it up into its subsystems and measure the interactions between those subsystems this paper was written by Roger C. Conant.
Joined: Oct 30, 2001
One of the previous posters said when a programming task looks too big, try to identify smaller parts of it that are more manageable. In your case, though, the homework-setter has already split the task down into its parts. (S)he has defined the classes and given strong hints what data and methods are needed.
Another previous poster said to develop and test little bits of the task separately, rather than trying to do the whole thing in one go. That is indeed a good thing to do.
An extra thing I would add is that you should translate all the wordy descriptions of the methods into method declarations (the name of the method and its parameters), before you try to write the bodies (implementations) of the methods.
Joined: May 11, 2007
Thank you very much for the kind words of advice etc...
I'll make a start and if possible post segments for your review here and there for additional input.