• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with assignment - Mini telephone book program please

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please consider whether an ArrayList is the correct data structure. Have a look at this section in the Java Tutorials.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

+ 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
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Alex Reynders
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic