Hello,


Could somebody help me with my problem:

I´ve got a Vector all. Data is: name, date, price@dateX

i will print out every person with name, and the amount (all prices together for that person)

How to do that??

Do you mean you have a class

which is contains the following:

name, date, price@dateX

and you wish to sort them according to their attributes. And btw, if you can avoid using vectors it is probably wise to do so. I think an arraylist is a better option.

In any case you need to explain your problem a bit more.

No, I´ve got a Vector, something like that:

public Vector data= new Vector();

data contains Objects with parameters: name, date, price@dateX

Now I want to make a summary like this:

name1 sum_of_prices
name2 sum_of_prices
name3 sum_of_prices
.
.
.

public void sum() {
		Purchase tempBuy;

		try {
			for (int i = 0; i < myData.size(); i++) {
				tempBuy= myData.give(i);
				
				Purchase name1=tempBuy;
				
				if(myData.give(i+1).getName()==myData.give(i).getName()){
					float summaryName1=myData.give(i+1).getPrice()+myData.give(i).getPice();
				
					
				}
				

			}
		} catch (NullPointerException e) {

		}

	}
public class Data implements Serializable {
	private Vector list= new Vector();

public void addPurchase(Purchase buy) {
		try {
			list.add(buy);
			save();
		} catch (Exception e) {
			System.out.println("Error");
		}

	}
public Purchase givePurchase(int i) {
		list.trimToSize();
		return ((Purchase) list.get(i));
	}
public void delete(int position) {
		list.removeElementAt(position);
		save();
	}

public void sum() {
        Purchase tempBuy;

        try {
            for (int i = 0; i < myData.size(); i++) {
                tempBuy= myData.give(i);
                
                Purchase name1=tempBuy;
                
                if(myData.give(i+1).getName()==myData.give(i).getName()){
                    float summaryName1=myData.give(i+1).getPrice()+myData.give(i).getPice();
                
                    
                }
                

            }
        } catch (NullPointerException e) {

        }

    } 
}

Not quite sure what you're trying to do.

Like I said before I still reckon you need to define a class with the following parameters:

name, date, price@dateX

Then you could create an array or possibly a vector of objects and thus sort them according to their attribute???

Er and no I don't know german.:cry:

This article has been dead for over six months. Start a new discussion instead.