public Cat(Pet p) { setPetType("Cat"); setId(p.getId()); setAge(p.getAge()); setPrice(p.getPrice()); setDescription(p.getDescription()); }
public Bird(Pet p) { setPetType("Bird"); setId(p.getId()); setAge(p.getAge()); setPrice(p.getPrice()); setDescription(p.getDescription()); }
public string ObjectToString(Pet obj) { MemoryStream ms = new MemoryStream(); new BinaryFormatter().Serialize(ms, obj); return Convert.ToBase64String(ms.ToArray()); }
public void addPet(Pet p) { string path = "c:\\Listing.txt"; string[] lines = System.IO.File.ReadAllLines(path); for (int x = 0; x < lines.Count(); x++) { string[] ind = lines[x].Split('\t'); if (ind.Count() > 3) { if (p.getId() == ind[3]) { return; } } } string result = ""; result += p.getPetType() + "\t"; switch (p.getPetType()) { case "Dog": Dog d = new Dog(); d = (Dog)p; result += d.getBreed() + "\t" + d.getColor() + "\t" + d.getId() + "\t" + d.getAge() + "\t" + d.getPrice() + "\t" + d.getDescription(); break; case "Cat": Cat c = new Cat(); c = (Cat)p; result += c.getBreed() + "\t" + c.getColor() + "\t" + c.getId() + "\t" + c.getAge() + "\t" + c.getPrice() + "\t" + c.getDescription(); break; case "Bird": Bird b = new Bird(); b = (Bird)p; result += b.getType() + "\t" + b.getWeight() + "\t" + b.getId() + "\t" + b.getAge() + "\t" + b.getPrice() + "\t" + b.getDescription(); break; } Debug.WriteLine(result); StreamWriter w = File.AppendText(path); w.WriteLine(result); w.Close(); }
public Dog(Pet p) { setPetType("Dog"); setId(p.getId()); setAge(p.getAge()); setPrice(p.getPrice()); setDescription(p.getDescription()); }