aspose file tools*
The moose likes Beginning Java and the fly likes Need help with assignment - Mini telephone book program please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help with assignment - Mini telephone book program please" Watch "Need help with assignment - Mini telephone book program please" New topic
Author

Need help with assignment - Mini telephone book program please

Alex Reynders
Greenhorn

Joined: Nov 16, 2008
Posts: 13
Hi guys,

I please need help your with this assignment please.

Here is my assignment specifications: (everything in bold.)


"
Create an application that will act as a mini telephone book -
The program must contain the functionality to :

1. Add new names and numbers
2. Enter a person's name to retrieve his/her number
3. Remove a person's name and number
4. Display a list of all the names and numbers added so far.

*1 Make sure the user enters the name and number in the correct format
and only adds information if it is in correct format. If information is entered
incorrectly, throw a custom-made exception and display an error message to the user.

*2 Make sure there are no duplicate entries

*3 When the user retrieves a number, make sure again that he/she enters the name in the correct format,
else throw another custom-made exception and display an error message to the user showing him/her that
the person does not exist.

*4 An option to remove the number should only be shown once the number has been retrieved

*5 Use a JTable placed inside a JScrollPane to show all the name-number pairs.

*6 Include an option where the user can see in what format the name and number should be.

*7 When the user chooses to exit, inform him/her that all the data will be lost and give him/her the option to
minimize, exit or cancel.
"


Now my problem is, is that I'm not sure if my code that I did so far is correct at all?

+ With point (*1) in the assignment specifications, I coded two textfields 'nameText' and 'numberText' to receive
the input from the user (which can be located in the 'actionPerformed () method in my code) and I also created
a custom-made exception method called 'checkInput()', but I'm not sure if Iv'e done this is correctly or not?

+ I do not know how to code point (*2) of the assignment specifications, I already created ArrayLists (one for
names and one for the numbers) but I do not know how to restrict it from duplicate entries?

(There are a few other things that I'm struggling with as well, but we'll take it a step at a time...)

Please Help me out with this.
Any other helpful comments is more than welcome.
Thank you so much.

PS - Sorry for the VERY long post but it was necessary to explain it all in detail

Below is my code that Iv'e treid so far:

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Please consider whether an ArrayList is the correct data structure. Have a look at this section in the Java Tutorials.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19072
    
  40

+ I do not know how to code point (*2) of the assignment specifications, I already created ArrayLists (one for
names and one for the numbers) but I do not know how to restrict it from duplicate entries?


It looks like you coded the check for duplicates -- what is it about your implementation that you "do not know how to" do?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
For keeping track of the 'telephone contacts' I thought maybe it would be easier to have a class
that keeps track of everything, even the actual contacts created.

here is the driver class:



And now the main:



And you could also write a lot of differenct static functions to get certain people and etc..

Now my question is, is the above code a good design? or is it too 'coupled'?
And maybe not this exact implementation, but the overall idea.

Thanks,

Justin


You down with OOP? Yeah you know me!
Alex Reynders
Greenhorn

Joined: Nov 16, 2008
Posts: 13
Hi guys,

Thanks for your quick and helpful responses.

I managed to get a lot of code done that works fine when I run my program but I still have a few issues...

What I'm still struggling with is these points: (from the assignment specs)

My first problem is at the line-

"and only adds information if it is in correct format" at the point (*1) in my assignment specs.

When I run the program, and input e.g. - 'abc' in the name and surname textfield and press enter
(which is wrong format), an error message is thrown via the 'messageLabel' at the bottom of the frame, thus far the program is doing what it is supposed to do.

Then I input e.g. - '9' in the phone number textfield and press enter (which is also in the wrong format), again an error message is thrown via the 'messageLabel' at the bottom of the frame, and so far so good.

But when I click on the 'ADD ENTRY' button, the program adds the entry although one or both of the textfields' input was incorrect.

I do not know how to rectify this problem, could you PLEASE help me with this?

My second problem is with "*5 Use a JTable placed inside a JScrollPane to show all the name-number pairs." -

I have created a new class called 'myTable' and in this table is all the code to create the JTable and the JScrollPane
I know that my code is incorrect, but my problem is, is that I do not know how to code a 'TreeMap'(which I'm using to store and store all the entries) to an array to use in the table.
What I want the program to do is when I click on the 'VIEW ALL ENTRIES' button it should call the 'myTable()' method from the 'myTable' class and output all the name-number pairs accordingly.

Please I need your help with this...

Here is my program code this far:



Further assistance from you guys would be much appreciated.
Thanks in advance
Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with assignment - Mini telephone book program please