Motorbike hashtable

T

Tuurbo46

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
 
B

Brendan Guild

Tuurbo46 wrote in news:[email protected]:
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: ");
}

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]
 
Z

zero

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top