java - .length error when trying to use a for loop with an ArrayList -


first off i'm sorry title couldn't think of better way word it. actual error in option 3(whenever try add sales in option 1). when try use saleslist.length track size of array cannot find symbol- variable length i'm new using array lists , method worked me in earlier array array wasn't dynamic. there specific way track length of dynamic array list?

import java.util.*; public class customertest { public static void main(string[] args)         {             double totalsales = 0;             arraylist<string> namelist;             namelist = new arraylist<string>();             arraylist<double> saleslist;             saleslist = new arraylist<double>();             scanner myscanner = new scanner(system.in);             boolean done = true;                              {                  system.out.println("1) add new customer \n 2) print customers \n 3) compute , print total sales \n 4) quit");                 int choice = integer.parseint(myscanner.nextline());                 if (choice == 1)                 {                     system.out.print("add new customer ");                     string answer = myscanner.nextline();                     namelist.add(answer);                     system.out.print("enter sales ");                     string answer2 = myscanner.nextline();                     double answer3 = double.parsedouble(answer2);                     saleslist.add(answer3);                 }                 else if(choice == 2)                 {                     system.out.println("customers: " + namelist);                     system.out.println("sales: " + saleslist);                 }                 else if(choice == 3)                 {                     for(int = 0; < saleslist.length; i++)                     {                      totalsales = totalsales + saleslist[i];                        }                      system.out.println(totalsales);                 }                 else if(choice == 4)                 {                     system.out.println("goodbye   *bows gracefully*");                      done = false;                 }                 else                     system.out.println("invalid choice");                  }             while (done);            system.exit(0);         } } 

change saleslist.size();. unlike arrays, length of arraylist not directly accessible field.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -