java - Getting cannot find symbol errors. ArrayLists, Iterator -


a supermarket wants reward top customers of day, is, topn customers largest sales, topn value user of program supplies, showing customer’s name on screen in supermarket. purpose, customer’s purchase amount stored in arraylist

implement method: public static arraylist

write program prompts cashier enter prices , names, adds them 2 array lists, calls method implemented, , displays result. use price of 0 sentinel.

my errors when compiling are:

------ compile ---------- hw1num2.java:44: error: cannot find symbol                 double check = iter.nextdouble();                                    ^   symbol:   method nextdouble()   location: variable iter of type iterator hw1num2.java:45: error: cannot find symbol                 if (check>=sorted(topn-1))                            ^  symbol:   method sorted(int) location: class hw1num2 hw1num2.java:47: error: no suitable method found add(double)                     topcust.add(check);                            ^    method arraylist.add(int,string) not applicable     (actual , formal argument lists differ in length)  method arraylist.add(string) not applicable  (actual argument double cannot converted string method invocatio>n conversion) 3 errors  output completed (1 sec consumed) - normal termination 

here's have:

import java.util.*;  public class hw1num2 {     public static void main(string[] args)      {         scanner in = new scanner(system.in);         arraylist<double> sales = new arraylist<double>();         arraylist<string> customers = new arraylist<string>();          boolean end = true;          while (end)  //continues take input customer names , purchases until done         {             system.out.println("enter first name of customer.");             string cust = in.next();             system.out.println("enter purchase total of customer.");             double total = in.nextdouble();             sales.add(total);             customers.add(cust);             system.out.println("enter 1 if have customer add, or 2 if done.");             int choice = in.nextint();             if (choice != 1)             {                 end=false;             }         }         system.out.println("how many top customers display?");         int topn = in.nextint();         system.out.println(nameofbestcustomers(sales, customers, topn));  //calls method computes top custs     }      public static arraylist<string> nameofbestcustomers(arraylist<double> sales, arraylist<string> customers,      int topn) //finds out topn customers     {         arraylist<double> sorted = new arraylist<double>(sales); //create copy of sales arraylist         arraylist<string> topcust = new arraylist<string>(); //create arraylist hold top cust names         collections.sort(sorted);  //sort copied arraylist.         iterator iter = sales.iterator();           while (iter.hasnext())  //iterate through sales arraylist find indexes of top purchases         {             (int i=0;i<sales.size();i++)             {                 double check = (double)iter.next();                  if (check>=sorted.get(topn-1)) //checks if each index >= top nth customer                 {                     topcust.add(customers.get(i)); //if so, adds topcust list                 }             }         }         return topcust;  //returns list top customer names     } } 

1- getting error because iterator class doesn't have method called nextdouble(). please have @ iterator api list of supported methods.

2- topcust string arraylist, cannot add double directly list.

3- p:s:your code here :

int choice = 1; if (choice != 1) {     end=false; } 

will cause endless while loop in main method.

hope helps.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -