javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

One of our teacher who used to work at the Supply Management of a company (logistics) told us that everybody where making requests for supplies saying that it was extremely urgent, so he could not decide which request to handle first.
Then he came up with the idea not to do anything and wait who would complain first about the delay and handle their request first

peter_budo commented: I like the way your teacher sorted problem ;) +8
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

My swing is a little rusty but if you add an Object in a comboBox, the toString() method will be displayed. And when you try to get the selected item it will return the entire object.

So have an object Person with attributes: name, percentage.
The Person should have a public String toString() { return name; } method.
So when you add the Person john with values:
name="John"
percentage=0.15
to the JComboBox it will be display what the toString method returns: "John"
When you do combo.getSelectedItem(); NOT combo.getSelectedIndex(); you will get the object Person:
Person selectedPerson = (Person)nameCombo.getSelectedIndex();
then selectedPerson will not only have the name but the percentage as well. So you will get it:
selectedPerson.getPercentage(); and multiply with whatever you want and set it to another field.
I have never tried the above approach, but I think that it will work. Also I hope I understood correctly you problem.

majestic0110 commented: Nice help. A true Java Addict :) ! +2
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I wrote:

Why did you create a new thread and ask the same question? If you didn't understand my answer at the previous thread then ask for more details or ask a better question.

I would like to apologize to both of you and whoever read this thread. I am sorry for the way I replied and I made a very big and silly mistake. Yesterday I was preparing a reply for this thread but before I submitted my internet connection went down and I could not connect again. So naturally I didn't submit any answer to the question. But I forgot about it, and today when I saw the thread again I thought that it was a new thread because I was so sure that I submited yesterday, but I didn't.
So I would like to apologize again for my manners and especially to KimJack.

Ezzaral commented: hehe oops! These things happen. +7
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Inside the compareTo method you will say how you want the objects to be compared.
Assume you have an Object with attributes name, height and weight.

If you want them to be sorted based on the height. write: (I don't remember the exact signature of compareTo so just pay attention to what is inside)

int compareTo(AnObject obj) {
 if (this.height>obj.height) return 1; //a positive number
 if (this.height<obj.height) return -1; //a negative number
 return 0; //if both heights are the same
}

Do the same if you want them to be sorted based on their weight.
Remember that equals is used for comparing if two objects have the same values so when the compareTo returns 0 doesn't necessary means that equals will return true. It may do, it do not.

About your case based on what you want them to be sorted? if it is based on Origin as you said, and if Origin is String then:

int compareTo(BookingResponse obj) {
   return Origin.compareTo(obj.Origin);
}

Or you can use your own criteria. Just remember to return positive, negative or 0 depending on how you want them to be compared

Ezzaral commented: Clear and helpful +6
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then use:
sdf.format(date);

The SimpleDateFormat.format(Date) will take any Date object, no matter how it was created and retutn a String based on the pattern you have set at the SimpleDateFormat object.
Meaning that this:

SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-mm-dd hh:mm:ss" );
Date date = new Date();
System.out.println("Date: " + sdf.format(date) );

will return:
2008-03-14 15:53:45

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest first to get the int value of the method and then check it if it is -1:

int i = name.indexOf(",");
if (i!=-1) 
  FirstName = name.substring(0,i);
piers commented: thnx you have helped me kill 2 birds with 1 stone +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No, no, no. The way I see it each Card object must represent a single card the suit, rank must not be arrays. The constructor will take the 2 values and you will pass these values to your class attributes.
Both attributes will be Strings. You will have no problem with suit. Just remember at the constructor to check: if the input suit is not “SPADES”,”DIAMONDS”,”CLUBS”,”HEARTS”, then throw an Exception or print an error message.
As for rank:
Now remember the constructor's rank will be int.
if the argument is between 2 and 10 just turn the int into a String

this.rank = String.valueOf(rank); //it will the int rank(argument) into a String and store it into the this.rank(String attribute of the class)

if it is 1,11,12,13 then put the necessary if-statements in order to store what is needed to rank. Then create 52 different Card objects (use 4 for-loops) and you have yourself a deck

piers commented: thnx 4 ur help +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Compile it, I think if you are console the command is >javac InputHandler.java (if I remember correctly because for a very long time I have been using IDEs) and run it with the command
>java InputHandler
Then the program will print the message in your code and then just insert the input.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since you don't know the size of the file why don't you put the strings you read into a Vector and then put the data from the Vector to an array
ex:
String line= readLine() from file
vector.add(line)

When you are done with the file use a for-loop to put the data into an array

PoovenM commented: Cool signature! Plus good advice :) +2