java - Carry over variable value to new method -
i'm new java , can't seem method working without having reset variable value of 'null' or new object. need have user input carry on next method.
public static void additem () { scanner console = new scanner(system.in); string desc, id, str=""; double price = 0, setupprice = 0, unitcost = 0, inventorycost = 0; int stock = 0, demand = 0; product product = new product(); system.out.print("please enter product description between 3 10 characters...: "); desc = console.next(); desc = desc.tolowercase(); product.setname(desc); /*if (desc.length < 3 || desc.length > 10) { system.out.print("this input incorrect, please try again."); }*/ system.out.print("please enter price in $ : "); price = console.nextdouble(); system.out.print("please enter set price. $ : "); setupprice = console.nextdouble(); system.out.print("please enter unit- cost. $ : "); unitcost = console.nextdouble(); system.out.print("please enter inventory cost. $ : "); inventorycost = console.nextdouble(); system.out.print("please enter amount in stock : "); stock = console.nextint(); system.out.print("please enter demand of product : "); demand = console.nextint(); // need code here repeat fuction again if y pressed. // if n pressed need return inventory management interface. } public static void proddata () { product product = new product(); system.out.println("the information product : "); system.out.println("product description : "+product.getname()); }
declare product var global , access follows
public static product product; public static void additem () { product = new product(); scanner console = new scanner(system.in); string desc, id, str=""; double price = 0, setupprice = 0, unitcost = 0, inventorycost = 0; int stock = 0, demand = 0; system.out.print("please enter product description between 3 10 characters...: "); desc = console.next(); desc = desc.tolowercase(); product.setname(desc); /*if (desc.length < 3 || desc.length > 10) { system.out.print("this input incorrect, please try again."); }*/ system.out.print("please enter price in $ : "); price = console.nextdouble(); system.out.print("please enter set price. $ : "); setupprice = console.nextdouble(); system.out.print("please enter unit- cost. $ : "); unitcost = console.nextdouble(); system.out.print("please enter inventory cost. $ : "); inventorycost = console.nextdouble(); system.out.print("please enter amount in stock : "); stock = console.nextint(); system.out.print("please enter demand of product : "); demand = console.nextint(); // need code here repeat fuction again if y pressed. // if n pressed need return inventory management interface. } public static void proddata () { system.out.println("the information product : "); system.out.println("product description : "+product.getname()); }
Comments
Post a Comment