You add
toString()
to yourCatalog
class asProduct
class :public class Catalog { private static int MAX_ITEMS = 10; /** * List of Products objects. */ private Products[] list; private int nextItem; // your old code here // new code @Override public String toString() { return "this is a catalog"; } }
You call
catalog.toString()
:
public static void main(String[] args) throws FileNotFoundException { Catalog catalog= new Catalog(); catalog.loadList(args[0]); System.out.println(); //System.out.println(toString()); **I don't know how to call toString** // use this line System.out.println(catalog.toString()); System.out.println(); System.out.format("Total Price = %9.2f\n", catalog.getTotalPrice()); }
- In your
toString()
method ofProduct
class. you should change initialize variable froms=null;
tos="";
. Here is sample :
public String toString(){ String s=""; s+=getName(); s+=s + " "; s+=getQuantity(); s+=s + " "; s+=getPrice(); return s; }
Hope this help :)