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??
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
.
.
.
What code do you have so far, can you post it?
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) {
}
}
Can you post your whole code, with especially where you used vectors.
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:
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.