I'm given the data.txt file and have to calculate the total amount using ArrayList
my data.txt file contains:
32.14,235.1,341.4,134.41,335.3,132.1,34.1
so far I have
public void processFile() throws IOException
{
File file = new File("SalesData.txt");
Scanner input = new Scanner(file);
ArrayList<String> arr = new ArrayList<String>();
String line = input.nextLine();
StringTokenizer st = new StringTokenizer(line, ",");
while (st.hasMoreTokens())
{
arr.add(st.nextToken());
}
setArrayListElement(arr); //calls setArrayListElement method
}
and here is my setArrayListElement method:
private void setArrayListElement(ArrayList inArray)
{
for (int i = 0 ; i < inArray.size() ; i++)
{
// need to convert each string into double and sum them up
}
}
Can I get some help??
Double.parseDouble()to convert aStringto adouble.