I am making an application which saves and loads information about products. These products have a product name, customer name and a firmware location. I have got them to save and load correctly, however I am now trying to find a way where I can search for a product on its name. Here is my products class:
//private product data
private string productName;
public string getProductName()
{
return this.productName;
}
public void setProductName (string inProductName)
{
this.productName = inProductName;
}
private string customerName;
public string getCustomerName()
{
return this.customerName;
}
public void setCustomerName (string inCustomerName)
{
this.customerName = inCustomerName;
}
private string firmwareLocation;
public string getFirmwareLocation()
{
return this.firmwareLocation;
}
public void setFirmwareLocation (string inFirmwareLocation)
{
this.firmwareLocation = inFirmwareLocation;
}
//constructor
public Product (string inProductName, string inCustomerName, string inFirmwareLocation)
{
productName = inProductName;
customerName = inCustomerName;
firmwareLocation = inFirmwareLocation;
}
//save method
public void Save (System.IO.TextWriter textOut)
{
textOut.WriteLine(productName);
textOut.WriteLine(customerName);
textOut.WriteLine(firmwareLocation);
}
public bool Save(string filename)
{
System.IO.TextWriter textOut = null;
try
{
textOut = new System.IO.StreamWriter(filename, true);
Save(textOut);
}
catch
{
return false;
}
finally
{
if (textOut != null)
{
textOut.Close();
}
}
return true;
}
public static Product Load (System.IO.TextReader textIn)
{
Product result = null;
try
{
string productName = textIn.ReadLine();
string customerName = textIn.ReadLine();
string firmwareLocation = textIn.ReadLine();
}
catch
{
return null;
}
return result;
}
}
}
I was wondering how I would search through the file say search a product name, and it would find it and display the product name, customer name and firmware location
See Question&Answers more detail:os