static void Main(string[] args) { ILoanableItem book = new Book(); ILoanableItem audioBook = new AudioBook(); ILoanableItem comic = new Comic(); LoanItem loanWithInLibrary = new LoanWithInLibrary(); loanWithInLibrary.Borrower = "Carlos Soliz"; loanWithInLibrary.BorrowDetails = "Date: 05/05/2021"; loanWithInLibrary.LoanableItem = book; loanWithInLibrary.Loan(); loanWithInLibrary.LoanableItem = audioBook; loanWithInLibrary.Loan(); loanWithInLibrary.LoanableItem = comic; loanWithInLibrary.Loan(); TakeOutLoan takeOutLoan = new TakeOutLoan(); takeOutLoan.Borrower = "Sarah Fernandez"; takeOutLoan.BorrowDetails = "Date: 05/05/2021"; takeOutLoan.ReturnDate = "07/06/2021"; takeOutLoan.BorrowerAddress = "Av. America # 1354"; takeOutLoan.LoanableItem = comic; takeOutLoan.Loan(); Console.ReadKey(); }
public List<Item> ParseFileContents() { List<Item> parsedItems = new List<Item>(); string bookPattern = @"Type:\sBook\sYear:\s(\d{4})\sTitle:\s(.*)\sISBN:(\d{10})\sPages:\s(.*)\sAuthors:(.*)"; string eBookPattern = @"Type:\seBook\sYear:\s(\d{4})\sTitle:\s(.*)\sISBN:(\d{10})\sPages:\s(.*)\sAuthors:(.*)File:(.*)"; string audioBookPattern = @"Type:\sAudioBook\sYear:\s(\d{4})\sTitle:\s(.*)\sISBN:(\d{10})\sDiscType:(CD|DVD|BlueRay)\sSeconds:(.*)"; string musicPattern = @"Type:\sMusic\sYear:\s(\d{4})\sTitle:\s(.*)\sDiscType:(CD|DVD|BlueRay)\sSeconds:(.*)"; string moviePattern = @"Type:\sMovie\sYear:\s(\d{4})\sTitle:\s(.*)\sDiscType:(CD|DVD|BlueRay)\sSeconds:(.*)"; Regex bookRegex = new Regex(bookPattern); Regex eBookRegex = new Regex(eBookPattern); Regex audioBookRegex = new Regex(audioBookPattern); Regex musicRegex = new Regex(musicPattern); Regex movieRegex = new Regex(moviePattern); using (StreamReader r = new StreamReader("LibraryCatalog-Input.txt")) { string line; while ((line = r.ReadLine()) != null) { Match m = bookRegex.Match(line); if (m.Success) { string year = m.Groups[1].Value.Trim(); string title = m.Groups[2].Value.Trim(); string isbn = m.Groups[3].Value.Trim(); string pages = m.Groups[4].Value.Trim(); string authors = m.Groups[5].Value.Trim(); Book myBook = new Book(Convert.ToUInt32(isbn), Convert.ToUInt16(year), Convert.ToUInt16(pages), title); string[] authorTokens = authors.Split(';'); foreach (string author in authorTokens) { string[] authorDetails = author.Split(','); myBook.setAuthors(new Author(authorDetails[0], authorDetails[1])); } parsedItems.Add(myBook); continue; } m = eBookRegex.Match(line); if (m.Success) { string year = m.Groups[1].Value.Trim(); string title = m.Groups[2].Value.Trim(); string isbn = m.Groups[3].Value.Trim(); string pages = m.Groups[4].Value.Trim(); string authors = m.Groups[5].Value.Trim(); string file = m.Groups[6].Value.Trim(); eBook myEbook = new eBook(Convert.ToUInt32(isbn), Convert.ToUInt16(year), Convert.ToUInt16(pages), title, file); string[] authorTokens = authors.Split(';'); foreach (string author in authorTokens) { string[] authorDetails = author.Split(','); myEbook.setAuthors(new Author(authorDetails[0], authorDetails[1])); } parsedItems.Add(myEbook); continue; } m = audioBookRegex.Match(line); if (m.Success) { string year = m.Groups[1].Value.Trim(); string title = m.Groups[2].Value.Trim(); string isbn = m.Groups[3].Value.Trim(); string discType = m.Groups[4].Value.Trim(); string seconds = m.Groups[5].Value.Trim(); DigitalDisc.DiscType dType = GetDiscType(discType); AudioBook myAudioBook = new AudioBook(Convert.ToUInt32(isbn), Convert.ToUInt16(year), title, dType, Convert.ToUInt16(seconds)); parsedItems.Add(myAudioBook); continue; } m = musicRegex.Match(line); if (m.Success) { string year = m.Groups[1].Value.Trim(); string title = m.Groups[2].Value.Trim(); string discType = m.Groups[3].Value.Trim(); string seconds = m.Groups[4].Value.Trim(); DigitalDisc.DiscType dType = GetDiscType(discType); Music myMusic = new Music(Convert.ToUInt16(year), title, dType, Convert.ToUInt16(seconds)); parsedItems.Add(myMusic); continue; } m = movieRegex.Match(line); if (m.Success) { string year = m.Groups[1].Value.Trim(); string title = m.Groups[2].Value.Trim(); string discType = m.Groups[3].Value.Trim(); string seconds = m.Groups[4].Value.Trim(); DigitalDisc.DiscType dType = GetDiscType(discType); Movie myMusic = new Movie(Convert.ToUInt16(year), title, dType, Convert.ToUInt16(seconds)); parsedItems.Add(myMusic); continue; } } } return parsedItems; }