Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Motorbike  hashtable

Thread view: 
Tuurbo46 - 28 Nov 2005 21:13 GMT
This post follows my previous post.  I am struggling to write to a
hashtable.  I have included more code this time. See below:

public void handleAddPlane()
   {

       String planeRegisNum = "";
       String planeModel = "";
       System.out.println("User wants to add a plane");

       System.out.println("Please enter plane registation number: ");
       planeRegisNum = readKeyboard().toUpperCase();
       while(planeRegisNum.equals("")){
            System.out.println("Wrong entry: ");
       }
       System.out.println("Please enter plane model number: ");
       planeModel = readKeyboard().toUpperCase();
       while(planeModel.equals("")){
            System.out.println("Wrong entry: ");
       }
       Block b[] = seatBlocks(planeModel);

       AirPlane plane = new AirPlane(b, planeRegisNum, planeModel);
       if (!airPlanes.containsKey(planeRegisNum))
       {
           try {
            airPlanes.put(planeRegisNum, plane);
           }
           catch(Exception ex){
               System.out.println("Problem Adding a Plane to a hash
table");
           }

          System.out.println("Airplane was successfully added");
       }

 }

Thanks tuurbo

Roedy Green - 28 Nov 2005 22:37 GMT
> I am struggling to write to a
>hashtable.

I don't see any code that implements a hashtable or even uses a
HashMap/Hashtable.  See http://mindprod.com/jgloss/hashtableh.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Rhino - 29 Nov 2005 04:47 GMT
>> I am struggling to write to a
>>hashtable.
>
> I don't see any code that implements a hashtable or even uses a
> HashMap/Hashtable.  See http://mindprod.com/jgloss/hashtableh.html

Also, the Subject talks about motorbikes but the code refers to airplanes.

Rhino
Roedy Green - 29 Nov 2005 06:23 GMT
On Mon, 28 Nov 2005 22:37:28 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :

>I don't see any code that implements a hashtable or even uses a
>HashMap/Hashtable.  See http://mindprod.com/jgloss/hashtableh.html

Whoops. Try  http://mindprod.com/jgloss/hashtable.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Brendan Guild - 29 Nov 2005 06:52 GMT
> public void handleAddPlane()
>     {
[quoted text clipped - 8 lines]
>              System.out.println("Wrong entry: ");
>         }

It's probably not important, but in the event planeRegisNum.equals(""),
this code will produce very strange results that I doubt are intended.
Otherwise I can't see anything wrong with what you have posted. Perhaps
you should try a simpler example. If you still have problems, it will be
easier for others to find those problems.

[snip]
zero - 29 Nov 2005 10:37 GMT
"Tuurbo46" <tuurbo46@yahoo.co.uk> wrote in news:dmfrtm$2eh$1
@news8.svr.pol.co.uk:

>         AirPlane plane = new AirPlane(b, planeRegisNum, planeModel);
>         if (!airPlanes.containsKey(planeRegisNum))
>         {
>             try {
>              airPlanes.put(planeRegisNum, plane);
>             }

The code that we need to see is the definition of "airPlanes" - and just to
be sure, anywhere in the code that mentions the "airPlanes" variable.

So not all your code, just the parts about "airPlanes".

Also, if you get an error, could you post the *exact* error message?

The code should be something like this

public class SomeClass
{
  private HashMap<String, AirPlane> airPlanes = new HashMap();

  ...

  public void handleAddPlane()
  {

     ...

     airPlanes.put(planeRegisNum, plane);
  }
}

Signature

Beware the False Authority Syndrome



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.