public class Item
{
/**
* @param args
*/
/**
* @param args
*/
private String name;
private double cost;
private int qty;
public Item(String name, double cost, int qty) {
this.name = name;
this.cost = cost;
this.qty = qty;
}
public String getName() {
return name;
}
public void setName(String Itemname) {
name = Itemname;
}
public double getCost() {
return cost;
}
public void setCost(double d) {
cost = d;
}
public int getQty() {
return qty;
}
public void setQty(int ItemQty) {
qty = ItemQty;
}
public static boolean ItemFound()throws FileNotFoundException
{
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
Item[]items = new Item[4];
items[0]= new Item("n",2.2,4);
items[0].setName("Oreo");
items[0].setCost(6.00);
items[0].setQty(10);
items[1]= new Item("n",2.2,4);
items[1].setName("Rice");
items[1].setCost(3.99);
items[1].setQty(20);
items[2]= new Item("n",2.2,4);
items[2].setName("Milk");
items[2].setCost(0.79);
items[2].setQty(75);
items[3]= new Item("n",2.2,4);
items[3].setName("Flour");
items[3].setCost(2.49);
items[3].setQty(5);
items[0].getName();
items[0].getCost();
items[0].getQty();
items[1].getCost();
items[1].getName();
items[1].getQty();
items[2].getName();
items[2].getCost();
items[2].getQty();
items[3].getName();
items[3].getCost();
items[3].getQty();
for(int i=0; i<items.length; i++)
{
if(input.equals(items[i].getName()))
{
return true;
}
}
return false;
}
public static void main(String[] args) throws FileNotFoundException
{
//Array array = new Array();
System.out.println("Please Enter the Item you Would Like to Purchase");
//Item[]items = new Item[4];
Item itm = new Item("d", 2.2, 3);
if(itm.ItemFound())
{
System.out.println("You are lucky, we found your Item.");
}
else
{
System.out.println("Did not find your item");
}
}
}
Right now it only prints whether the item is found or not but please let me know how I can print the found item along with the the name, quantity and the cost. I have tried many ways but haven't been successful... Please help me with this.