public void Save() { // Open stream to argument file and override existing file if it exists (don't append). this.sw = new StreamWriter(DEFAULT_SAVE_FILE, APPEND); foreach (IValuable o in this.valuables) { if (o is Book) { Book book = o as Book; sw.WriteLine("{0};{1};{2};{3}", "BOG", book.ItemId, book.Title, book.Price); } if (o is Amulet) { Amulet amulet = o as Amulet; sw.WriteLine("{0};{1};{2};{3}", "AMULET", amulet.ItemId, amulet.Quality, amulet.Design); } if (o is Course) { Course course = o as Course; sw.WriteLine("{0};{1};{2}", "COURSE", course.Name, course.DurationInMinutes); } } this.sw.Close(); }
public void Load(string fileName) { this.sr = new StreamReader(fileName); string line; while ((line = sr.ReadLine()) != null) { string[] o; o = line.Split(";"); switch (o[0]) { case "BOG": Book book = new Book(o[1], o[2], double.Parse(o[3])); AddValuable(book); break; case "AMULET": Amulet amulet = new Amulet(o[1], (Level)Enum.Parse(typeof(Level), o[2]), o[3]); AddValuable(amulet); break; case "COURSE": Course course = new Course(o[1], int.Parse(o[2])); AddValuable(course); break; default: break; } } this.sr.Close(); }
public static double GetValueOfMerchandise(Merchandise merchandise) { if (merchandise is Book) { Book book = merchandise as Book; return(book.Price); } if (merchandise is Amulet) { Amulet amulet = merchandise as Amulet; switch (amulet.Quality) { case Level.low: return(LowQualityValue); case Level.medium: return(MediumQualityValue); case Level.high: return(HighQualityValue); default: return(0.0); } } return(0.00); }
public static double GetValueOfAmulet(Amulet a11) { if (a11.Quality.ToString() == "low") { return(12.5); } else if (a11.Quality.ToString() == "high") { return(27.5); } else { return(20.0); } }
public void AddAmulet(Amulet a) { amulets.Add(a); }