using System; using
//CHANGE - add the appropriate namespace for file input and output
namespace Inventory {
class Inventory {
private FileInfo inventoryFile;
//CHANGE - create a private string object called textLine
//CHANGE - make the private attribute outputFile a file output
stream for writing
//CHANGE - make the private attribute inputFile a file input
stream for reading
public Inventory() {
this.textLine = "";
try { inventoryFile = new FileInfo("INVENTORY");
outputFile = inventoryFile.CreateText();
} catch (IOException exObj) { System.Console.WriteLine(exObj);
} inputFile = null;
}
//CHANGE - create a setter for textLine
//CHANGE - create a getter for textLine
public void WriteInventory() { try {
outputFile.Close();
outputFile = inventoryFile.AppendText();
System.Console.Write(" Enter the number of units:");
textLine = System.Console.ReadLine();
outputFile.Write(textLine + "___");
System.Console.Write(" Enter the description :");
textLine = System.Console.ReadLine();
outputFile.WriteLine(textLine);
outputFile.Close();
}
catch (IOException exObj) { System.Console.WriteLine(exObj); }
} public void ReadInventory()
{
try { inputFile = inventoryFile.OpenText();
textLine = inputFile.ReadLine();
System.Console.WriteLine("\nReading Inventory");
while (textLine != null) { System.Console.WriteLine(textLine);
textLine = inputFile.ReadLine();
}
inputFile.Close();
} catch (IOException exObj)
{ System.Console.WriteLine(exObj); }
}
public static void Main (string[] args)
{
//CHANGE - create an Inventory object called checkInventory
string keyboard = "x";
do {
//CHANGE - call the method to write inventory
//CHANGE - call the method to read inventory
System.Console.WriteLine( "Press x to exit or any key to continue");
keyboard = System.Console.ReadLine(); } while (keyboard != "x"); }
}
}