Darrin
ThreeArrayList
1 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners

I can't get the message to output in my software Eclispe. I need this by 5pm CST...Thank You'

package tal;
import java.util.ArrayList;

public class ThreeArrayLists
{
public static void main(String[] args) {
ArrayList priceList = new ArrayList();
ArrayList quantityList = new ArrayList();
ArrayList amountList = new ArrayList();

priceList.add(new Double(10.62));
priceList.add(new Double(14.89));
priceList.add(new Double(13.21));
priceList.add(new Double(16.55));
priceList.add(new Double(18.62));
priceList.add(new Double(9.47));
priceList.add(new Double(6.58));
priceList.add(new Double(18.32));
priceList.add(new Double(12.15));
priceList.add(new Double(3.98));

quantityList.add(new Double(4.0));
quantityList.add(new Double(8.5));
quantityList.add(new Double(6.0));
quantityList.add(new Double(7.35));
quantityList.add(new Double(9.0));

quantityList.add(new Double(15.3));
quantityList.add(new Double(3));
quantityList.add(new Double(5.4));
quantityList.add(new Double(2.9));
quantityList.add(new Double(4.8));

for(int i = 0; i < 10; i++)
{
amountList.add((Double.valueOf(priceList.get(i).toString())) * (Double.valueOf(quantityList.get(i).toString())));
System.out.printf("%d)%.2f*%.2f = %.2f\n", i + 1, Double.valueOf(priceList.get(i).toString()),
Double.valueOf(quantityList.get(i).toString()), Double.valueOf(amountList.get(i).toString()));
}
}
View Answers

February 15, 2010 at 10:40 AM


Hi Friend,

Try it:

import java.util.ArrayList;

public class ThreeArrayLists{
public static void main(String[] args) {
ArrayList priceList = new ArrayList();
ArrayList quantityList = new ArrayList();
ArrayList amountList = new ArrayList();

priceList.add(new Double(10.62));
priceList.add(new Double(14.89));
priceList.add(new Double(13.21));
priceList.add(new Double(16.55));
priceList.add(new Double(18.62));
priceList.add(new Double(9.47));
priceList.add(new Double(6.58));
priceList.add(new Double(18.32));
priceList.add(new Double(12.15));
priceList.add(new Double(3.98));

quantityList.add(new Double(4.0));
quantityList.add(new Double(8.5));
quantityList.add(new Double(6.0));
quantityList.add(new Double(7.35));
quantityList.add(new Double(9.0));
quantityList.add(new Double(15.3));
quantityList.add(new Double(3));
quantityList.add(new Double(5.4));
quantityList.add(new Double(2.9));
quantityList.add(new Double(4.8));

for(int i = 0; i < 10; i++){
amountList.add((Double.valueOf(priceList.get(i).toString())) * (Double.valueOf(quantityList.get(i).toString())));
System.out.printf("%d)%.2f*%.2f = %.2f\n", i + 1, Double.valueOf(priceList.get(i).toString()),
Double.valueOf(quantityList.get(i).toString()), Double.valueOf(amountList.get(i).toString()));
}
}
}

Anyways, if you got error again then send the error also.

Thanks









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.