Java Beginner - Cannot find symbol- variable -
not sure whats causing error here, when enter value in string name upon creation of item.
any appreciated, cause im pretty stuck @ moment
public class item { double itemcode; string itemname; double itemprice; public item(){ } public item(double code, string name, double price){ itemcode = code; itemname = name; itemprice = price; } public string getcode(){ return string.valueof(itemcode); } public void setcode(double itemcode){ this.itemcode = itemcode; } public string getfirstname(){ return itemname; } public void setfirstname(string itemname){ this.itemname = itemname; } public string getprice(){ return string.valueof(itemprice); } public void setprice(double itemprice){ this.itemprice = itemprice; } public string tostring(){ return (string.valueof(itemcode) + ": " + itemname + ", £" + string.valueof(itemprice)); } }
correct way initialize object
item item = new item(1.0d,"item",10.0d);
you cannot variable x
item item = new item(1.0d, x, 10.0d);
if want value x should
item item = new item(1.0d, "x", 10.0d);
or
string x = "x"; item item = new item(1.0d, x, 10.0d);
Comments
Post a Comment